Differences

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

Link to this comparison view

dev:jdbc:sample [2011/01/12 22:17]
els
dev:jdbc:sample [2016/06/28 22:38]
Line 1: Line 1:
-{{page>:​top_add&​nofooter&​noeditbtn}} 
- 
-====== Development:​ JDBC Interface ====== 
- 
-[[dev:​jdbc:​home|Overview]] | **[[dev:​jdbc:​sample|Sample Java Program]]** 
- 
----- 
- 
- 
-===== Sample JDBC Program ===== 
- 
-The following is a very simple Java program that shows a basic connection to an Omnidex Environment and simple query processing. 
- 
-<code java> 
-<code java> 
- 
-/* Omnidex JDBC Example: Simple Select */ 
- 
-import java.io.*; 
-import java.sql.*; 
-  
-public class OdxJDBCSample { 
-  
-public OdxJDBCSample() { } 
-  
-// 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 File 
-  try 
-  { 
-    odxconn = DriverManager.getConnection 
-       ("​jdbc:​omnidex:​[server1:​7555]c:​\\class\\simple.xml"​);​ 
-  } 
-  catch(SQLException se)  
-  { 
-    System.out.println("​Connect error: " + se); 
-    System.exit(0);​ 
-  } 
-    
-  // The SQL statement to be executed ​ 
-  String sql = "​select NAME, PHONE from INDIVIDUALS";​ 
-  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) + "​\t"​);​ 
-      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 
-</​code>​ 
- 
-=====  ===== 
- 
-**[[dev:​jdbc:​home|Prev]]** 
- 
-====== Additional Resources ====== 
- 
-See also:  
- 
-{{page>:​dev:​see_also&​nofooter&​noeditbtn}} 
- 
-{{page>:​bottom_add&​nofooter&​noeditbtn}} 
  
 
Back to top
dev/jdbc/sample.txt ยท Last modified: 2016/06/28 22:38 (external edit)