This is an old revision of the document!


JDBC Example: Simple Select Statement

// Omnidex JDBC Example: Simple Select
import java.io.*;
import java.sql.*;
public class OdxSimpleSelect {
 
public OdxSimpleSelect() { }
 
// 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
 
Back to top
dev/jdbc/examples/simpleselect.1258610794.txt.gz ยท Last modified: 2016/06/28 22:38 (external edit)