DRAFT

Java JDBC Omnidex Simple Connection/Select

Quick Notes

Java Sample Code

/** 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 odxconn = null;
  Statement odxstmt = null;
  ResultSet odxrs = null;
 
// Register the Omnidex JDBC driver 
try{Class.forName("omnidex.jdbc.OdxJDBCDriver");}
catch(ClassNotFoundException ce) 
{
  System.out.println("Driver error: " + ce);
  System.exit(0);
}
// Connect to the Omnidex Environment Catalog via a File DataSource
// DISC recommends using a connection string instead of a data source.
try
{
  odxconn = DriverManager.getConnection
	     ("jdbc:omnidex:c:\\dev\\odx\\tiny\\tiny.dsn");
}
catch(SQLException se) 
{
  System.out.println("Connect error: " + se);
  System.exit(0);
}
 
// The SQL statement to be executed 
String sql = "select * from table1";
try
{
  odxstmt = odxconn.createStatement();
  odxstmt.execute(sql);
  odxrs = odxstmt.getResultSet();
 
// Print the results from the Result Set returned after the Select
  while(odxrs.next())
  {
    System.out.print(odxrs.getString(1) + "\n");
    System.out.println(odxrs.getString(2)); 
  } 
} 
catch(SQLException se) 
{
  System.out.println("Execute query error: " + se);
}
 
// Close the Result Set, Statement and Connection objects */
try
{
  if(odxrs != null) odxrs.close();
  if(odxstmt != null) odxstmt.close();
  if(odxconn != null) odxconn.close();
}
catch(SQLException se) 
{
  System.out.println("Close error: " + se);
}
 
System.out.println("End of program.");
 
} // End Main
} // End Class