Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
dev:jdbc:examples:simpleselect [2009/11/19 00:15]
tdo
dev:jdbc:examples:simpleselect [2016/06/28 22:38] (current)
Line 1: Line 1:
-====== JDBC ExampleSimple Select Statement ======+{{page>:​top_add&​nofooter&​noeditbtn}} 
 +<​html><​div align="​center"><​span style="color:red">​DRAFT</​span></​div></​html>​
  
-<​code>​ +====== Java JDBC Omnidex Simple Connection/​Select ====== 
-/Omnidex JDBC Example: Simple Select+^ [[dev:home | Dev ]] ^ [[dev:​odbc:​examples:​simpleselect | C++ ]] ^ [[dev:​odbc:​examples:​csharp_simple_select |C# ]] ^ [[dev:​jdbc:​examples:​simpleselect | Java ]] ^ [[dev:​odbc:​examples:​php_select | PHP ]] ^ 
 + 
 +===== Quick Notes ===== 
 +  * Make sure the Java SDK is properly installed. Refer to the installation instructions accompanying the Java SDK. 
 +  * Make sure the Omnidex server software is properly installed on the server. 
 +  * Make sure the Orders sample database is properly installed with Omnidex. 
 +  * Start an Omnidex Network Server listener on the server. 
 +  * Make sure the Omnidex client software is properly installed on the client and the omnidex.jar file is in the CLASSPATH. 
 +  * Create an Omnidex Data Source using Data Source Editor (DSEDIT) that connects to the orders sample database on the server, through the running Omnidex Network Server listener. This Data Source must be a File data source. 
 +  * Modify the OdxJDBCTest.java file (shown below). 
 +  * Compile and run OdxJDBCTest java program. 
 + 
 +===== Java Sample Code ===== 
 + 
 +<​code ​java
 +/** Omnidex JDBC Example: Simple Select ​ 
 +*/
 import java.io.*; import java.io.*;
 import java.sql.*; import java.sql.*;
 + 
 public class OdxSimpleSelect { public class OdxSimpleSelect {
- +  
-public OdxSimpleSelect() { +public OdxSimpleSelect() { } 
-+ 
 // Main  // Main 
 public static void main(String[] args){ public static void main(String[] args){
 + 
 // Declare JDBC objects ​ // Declare JDBC objects ​
- Connection ​conn = null; +  ​Connection ​odxconn ​= null; 
- ​Statement ​stmt = null; +  Statement ​odxstmt ​= null; 
- ​ResultSet ​rs = null; +  ResultSet ​odxrs = null; 
 + 
 // Register the Omnidex JDBC driver ​ // Register the Omnidex JDBC driver ​
- try{ +try{Class.forName("​omnidex.jdbc.OdxJDBCDriver"​);​} 
- Class.forName("​omnidex.jdbc.OdxJDBCDriver"​);​ +catch(ClassNotFoundException ce)  
- }catch(ClassNotFoundException ce) { +
- pw.println("​Driver error: " + ce); +  System.out.println("​Driver error: " + ce); 
- System.out.println("​Driver error: " + ce); +  System.exit(0);​ 
- ​System.exit(0);​ +
- } +// Connect to the Omnidex Environment Catalog ​via a File DataSource 
- +// DISC recommends using a connection string instead of a data source. 
-// Connect to the Omnidex Environment Catalog +try 
- ​try{ +
- conn = DriverManager.getConnection +  ​odxconn ​= DriverManager.getConnection 
- "​jdbc:​omnidex:​c:​\\odxtesting\\dsn\\odx_file_ordersffl.dsn"​);​ +      ("​jdbc:​omnidex:​c:​\\dev\\odx\\tiny\\tiny.dsn"​);​ 
- +} 
- }catch(SQLException se) { +catch(SQLException se)  
- pw.println("​Connect error: " + se); +
- System.out.println("​Connect error: " + se); +  System.out.println("​Connect error: " + se); 
- ​System.exit(0);​ +  System.exit(0);​ 
- } +
 + 
 // The SQL statement to be executed ​ // The SQL statement to be executed ​
- String sql = "​select * from customers where state='​co'​"; +String sql = "​select * from table1"; 
- ​try{ +try 
- stmt conn.createStatement();​ +
- stmt.execute(sql);​ +  ​odxstmt ​odxconn.createStatement();​ 
- rs stmt.getResultSet();​ +  ​odxstmt.execute(sql);​ 
 +  ​odxrs ​odxstmt.getResultSet();​ 
 + 
 // Print the results from the Result Set returned after the Select // Print the results from the Result Set returned after the Select
- while(rs.next()){ +  ​while(odxrs.next()) 
- ​System.out.print(rs.getString(1) + "​\n"​);​ +  ​
- ​System.out.print(rs.getString(2) ​+ "​\n"​); +    System.out.print(odxrs.getString(1) + "​\n"​);​ 
- System.out.print(rs.getString(3) + "​\n"​);​ +    System.out.println(odxrs.getString(2));​  
- ​System.out.println(rs.getString(4)); ​ +  ​} ​ 
- } +}  
- }catch(SQLException se) { +catch(SQLException se)  
- ​System.out.println("​Execute query error: " + se); +
- }+  System.out.println("​Execute query error: " + se); 
 +}
    
 // Close the Result Set, Statement and Connection objects */ // Close the Result Set, Statement and Connection objects */
- try{ +try 
- if(rs != null) rs.close(); +
- if(stmt != null) stmt.close(); +  if(odxrs != null) odxrs.close(); 
- if(conn != null) conn.close(); +  if(odxstmt ​!= null) odxstmt.close(); 
- ​}catch(SQLException se) { +  if(odxconn ​!= null) odxconn.close(); 
- ​System.out.println("​Close error: " + se); +} 
- } +catch(SQLException se)  
- ​System.out.println("​End of program."​);​+
 +  System.out.println("​Close error: " + se); 
 +} 
 +  
 +System.out.println("​End of program."​);​ 
 + 
 } // End Main } // End Main
 } // End Class } // End Class
 </​code>​ </​code>​
 
Back to top
dev/jdbc/examples/simpleselect.1258589731.txt.gz · Last modified: 2016/06/28 22:38 (external edit)