This is an old revision of the document!
// Omnidex JDBC Example: Simple Select
import java.io.*;
import java.sql.*;
public class OdxJDBCTest {
public OdxJDBCTest() {
}
// Main
public static void main(String[] args){
// Declare JDBC objects
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
// Register the Omnidex JDBC driver
try{
Class.forName("omnidex.jdbc.OdxJDBCDriver");
}catch(ClassNotFoundException ce) {
pw.println("Driver error: " + ce);
System.out.println("Driver error: " + ce);
System.exit(0);
}
// Connect to the Omnidex Environment Catalog
try{
conn = DriverManager.getConnection(
"jdbc:omnidex:c:\\odxtesting\\dsn\\odx_file_ordersffl.dsn");
}catch(SQLException se) {
pw.println("Connect error: " + se);
System.out.println("Connect error: " + se);
System.exit(0);
}
// The SQL statement to be executed
String sql = "select * from customers where state='co'";
try{
stmt = conn.createStatement();
stmt.execute(sql);
rs = stmt.getResultSet();
// Print the results from the Result Set returned after the Select
while(rs.next()){
System.out.print(rs.getString(1) + "\n");
System.out.print(rs.getString(2) + "\n");
System.out.print(rs.getString(3) + "\n");
System.out.println(rs.getString(4));
}
}catch(SQLException se) {
System.out.println("Execute query error: " + se);
}
// Close the Result Set, Statement and Connection objects */
try{
if(rs != null) rs.close();
if(stmt != null) stmt.close();
if(conn != null) conn.close();
}catch(SQLException se) {
System.out.println("Close error: " + se);
}
System.out.println("End of program.");
} // End Main
} // End Class