Hi,
I have a new Vista, my old XP died. I am having difficulty executing a simple JDBC/java progam to access oracle db. When I worked before, I was using
9g. Now it is 10g. I can not figure out if thin client is to be used or OCI. I used both of them before. Where to place the classes12.jar or another one that goes with oci driver. And how to do classpath? Your help will be greatly appreciated. Thanks
My code is as follows:
import java.sql.*; // JDBC package
//import com.inet.tds.JDBCRowSet;
import java.util.*;
// import oracle.jdbc.driver.*;
// import oracle.sql.*;
public class HomeDB
{
/*
run as follows:
C:\Documents and Settings\silia>cd \jj
C:\john>set CLASSPATH=.;c:\oracle9i\classes12;%CLASSPATH%
C:\john>javac HomeDB.java
C:\john>java HomeDB
King: 24000.0
Kochhar: 17000.0
De Haan: 17000.0
Hunold: 9000.0
Ernst: 6000.0
Austin: 4800.0
*/
public static void main(String[] argv)throws SQLException
{
Connection conn=null;
try // may throw a SQLException
{
conn = getConnection();
doQuery (conn);
}
catch (SQLException e)
{
System.err.println(e.getErrorCode() + ": " + e.getMessage());
}
finally // make sure the connection is closed
{
if (conn != null) try {conn.close();} catch (SQLException e) {};
}
//out.close(); // close PrintWriter stream
}
private static Connection getConnection() throws SQLException
{
String username = "scott";
String password = "tiger";
String url = "jdbc

racle:thin:@localhost:1521:newora";
// "jdbc

racle:thin:@localhost:1521:COCKYJOB";
Connection conn = null;
String driver = "oracle.jdbc.driver.OracleDriver";
try {
Class.forName("oracle.jdbc.driver.OracleDriver").n ewInstance();
} catch ( ClassNotFoundException cnfex ) {
System.err.println(
"Failed to load JDBC/ODBC driver." );
cnfex.printStackTrace();
}catch (Exception e){
e.printStackTrace();
}
//DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
conn = java.sql.DriverManager.getConnection(url,username, password);
conn.setAutoCommit(false);
return conn;
}
private static void doQuery (Connection c) throws SQLException
{
// statement to be executed
String query = "SELECT ename, job, mgr FROM EMP";
Statement st = null;
ResultSet rs = null;
try // make sure the close statements are executed (in the finally block)
{
// create the statement
st = c.createStatement();
// execute the query
rs = st.executeQuery(query);
// process results
while (rs.next())
{
// get the employee last name
String eName = rs.getString("ename");
String eJob = rs.getString("job");
String eMgr = rs.getString("mgr");
System.out.println("Emp Name:" + eName +
"Job: " + eJob +
"MGR: " + eMgr);
}
}
finally // make sure the close statements are executed
{
// close the result set if it exists
if (rs != null) try {rs.close();} catch (Exception e) {};
// close the statement if it exists
if (st != null) try {st.close();} catch (Exception e) {};
}
}
}