Illustration of Dynamic SQL Queries
This application shows how to create and execute dynamic sql queries using JDBC. The user selects a table from his schema, then the columns and provides the where clause. The dynamic SQL query is then formed based on the user input and executed. The sample uses the JDBC-Thin driver; the code is the same for JDBC-OCI, except for the database URL syntax. Steps in the Sample :
|
Required Software |
Installation and Configuration |
The section has step-by-step
instructions to run this application successfully.
This will be discussed in the following subsections
Run the sample using Oracle9i JDeveloper
Run the sample using the JDK environment
Step 1. Unjar DynamicSqlSample.jar using Winzip, or using the following command:
> jar xvf DynamicSqlSample.jar
You will find jar.exe in JDK_HOME\bin. Ensure that JDK_HOME\bin is present in your system path. (JDK_HOME is the root directory of the JDKx.x installation ).
This creates a folder DynamicSqlSample with all the source files
Step 2. Edit Connection.properties file located in the directory DynamicSqlSample\src. Change the attributes hostname, portnumber and database name to those of the database instance you want to connect to.
Change the following lines:
HostName = insn104a.idc.oracle.com SID = otn9i Port = 1521 UserName = scott Password = tiger
Step 1. Using JDeveloper File/Open option select the DynamicSqlSample.jws from the DynamicSqlSample directory.
Step 2. Select Project/Make from JDeveloper main menu and select Make Project "DynamicSqlSample.jpr"
Step 3. Select Run/Run DynamicSqlSample.jpr
from JDeveloper main menu to run the application.
Step 1. Install
Oracle JDBC Driver and include the zip/jar files in the CLASSPATH
Ensure
that DynamicSqlSample\src directory is added to the CLASSPATH
Step 2. Change directory to DynamicSqlSample\src\oracle\otnsamples\jdbc\dynamicsql.
Compile the files using javac:
%javac *.java
Step 3. Run the class file using java:
%java
oracle.otnsamples.jdbc.dynamicsql.DynamicSqlSample
Description of Sample Files |
DynamicSqlSample is the top level directory.
|
Directory
|
Files
|
Description
|
| DynamicSqlSample | ReadMe.html | This file |
| DynamicSqlSample.jws | The Oracle9i JDeveloper workspace file | |
| DynamicSqlSample.jpr | The Oracle9i JDeveloper project file | |
| DynamicSqlSample\src | Connection.properties | This file has the details of the database connection parameters |
| DynamicSqlSample\src\oracle\otnsamples\jdbc\dynamicsql | DynamicSqlSample.java | The source file for sample |
| DynamicSqlFrame.java | The source file for the sample User Interface | |
| GenTableModel.java | The source file for the GenTableModel class, which handles the JTable data |