Invoking DQL in Java applications

Read(1809) Label: dql, java, dql jdbc,

Using the Java language as an example, this subsection is a quick guide to connection to DQL through JDBC.

There are two methods to establish a connection to DQL through JDBC:

Method 1: Deploy and start DQL Server. The process is displayed in Deploying DQL server. Below is the code example:

 

public void DQLServerJDBC() {

Connection con=null;

try {

// Establish a connection

Class.forName("com.esproc.dql.jdbc.DQLDriver");

con = DriverManager.getConnection("jdbc:esproc:dql:// 127.0.0.1:3368/datalogic","sa","sa");

// Create and execute DQL statement

PreparedStatement stmt = con.prepareStatement("SELECT EmpID,Name FROM Employee", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

ResultSet set = stmt.executeQuery();

…….

} catch (SQLException e){

System.out.println(e);

}finally{

// Close data set

if (con!=null) con.close();

}  

}

Method 2: Embedded DQL JDBC. The process is explained in Embedded DQL deployment. Below is the code example:

public void DQLJDBC() {

Connection con=null;

try {

// Establish the connection

Class.forName("com.esproc.dql.jdbc.DQLDriver");

// Related files, including configuration file and metadata file, are located in the project’s classpath

con = DriverManager.getConnection("jdbc:esproc:dql://?config=raqsoftConfig.xml&glmd=demo.glmd&gdct=demo.gdct");

// Write and execute the DQL statement

PreparedStatement stmt = con.prepareStatement("SELECT EmpID,Name FROM Employee", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

ResultSet set = stmt.executeQuery();

…….

} catch (SQLException e){

System.out.println(e);

}finally{

// Close the dataset

if (con!=null) con.close();

}

}