/* * This sample shows how to list all entries from the table dogs in the database * * It uses the JDBC OCI8 driver. See the same program in the * thin or oci7 samples directories to see how to use the other drivers. */ // You need to import the java.sql package to use JDBC import java.sql.*; //You need to import the math package import java.math.*; class TestCSUH3 { public static void main (String args []) throws SQLException, ClassNotFoundException { // Load the Oracle JDBC driver Class.forName ("oracle.jdbc.driver.OracleDriver"); // Connect to the database // You can put a database name after the @ sign in the connection URL. // Next parameter= login, Next = password //WORKS1 //relies on fact that labdb is setup inside of the tnsnames.ora file to point // to bosack server, port 1512, sid labdb // Connection conn = // DriverManager.getConnection ("jdbc:oracle:oci8:@labdb", "lgrewe", "lgrewe"); //WORKS2 //uses full SQLNet address // Connection conn = // DriverManager.getConnection //("jdbc:oracle:oci8:@(description=(address_list=(address=(protocol=tcp)(host=134.154.11.126//)(//port=1521)))(connect_data=(sid=labdb)))", "lgrewe", "lgrewe"); //Here we are connecting to server bosack (134.154.11.126) at port 1521 and sid labdb try{ Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@134.154.11.126:1521:labdb","lgrewe","lgrewe"); //DOESNT WORK //Error: java.lang.NullPointerException, Stack trace is disabled. Set JAVA_COMCMD=STA to //enable //DriverManager.getConnection ("jdbc:oracle:thin:@labdb", "lgrewe", "lgrewe"); //DOESNT WORK ALL SAME SQL_EXCEPTION = //Message = NO MORE DATA TO READ ON SOCKET, SQLState= null, Error Code=0 //DriverManager.getConnection //("jdbc:oracle:thin:@(description=(address_list=(address=(protocol=tcp)(host=134.154.11.126//)(port=1521)))(connect_data=(sid=labdb)))", "lgrewe", "lgrewe"); //TRIAL 1 //DriverManager.getConnection("jdbc:oracle:thin:@134.154.11.126:1521:labdb","lgrewe","lgrewe"); //TRIAL 2 //DriverManager.getConnection("jdbc:oracle:thin:@bosack.telecom.csuhayward.edu:1521:labdb","//lgrewe","lgrewe"); //DOESN'T WORK SQL_EXCEPTION = //Message = ORA-06401: NETCMN: invalid driver designator // SQLState= , Error Code=6401 //LOOKED UP and means: You are using an older version of SQL*Net. The version of Oracle on //the client may be older than Oracle7.3.4. Install Oracle7.3.4 on the client. //DriverManager.getConnection("jdbc:oracle:oci8:@134.154.11.126:1521:labdb","lgrewe","lgrewe//"); // Create a Statement Statement stmt = conn.createStatement (); // Select the all (*) from the table JAVATEST // ResultSet rset = stmt.executeQuery ("select * from system.JAVATEST"); ResultSet rset = stmt.executeQuery("select * from dogs"); System.out.println(rset); // Iterate through the result and print the employee names while (rset.next ()) //get next row of table returned { for(int i=1; i