I have tried this code in both JDeveloper 10g and Netbeans 3.5. I cannot get the DriverManager to recognize the oracle driver. I can connect to the database, but the driver isn't recognized. Here's my code:
//register the Oracle JDBC DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
//create the connection object, and connect to the database // as user_name using the thin driver //myConnection = DriverManager.getConnection("jdbc.default.connection"); myConnection = DriverManager.getConnection("jdbc racle:thin@urlparameter", "login", "pwd");
//create a Statement object myStatement = myConnection.createStatement();
//create variables and objects to represent field values int id = 40000419; double no = 0.01; String whatString = "A Java test to see if Java classes are viable."; java.sql.Date v_date = new java.sql.Date(2004, 3, 10);
//perform sql update to modify the what field of the Project Derscription section myStatement.executeUpdate( "Update table_name " + "Set whatString = ' " + what + "' " + "Where id = " + id ); System.out.println("Updated row in thre tablename table.");
//Create a ResultSet object, and populate it with the result set of //the SELECT statement that retrieves a given row of data ResultSet requestResultSet = myStatement.executeQuery( "Select id, no, v_date, whatString " + "From tablename " + "Where id between " + id + "and " + "999" );
while(requestResultSet.next()) { id = requestResultSet.getInt("id"); no = requestResultSet.getDouble("no"); v_date = requestResultSet.getDate("v_date"); whatString = requestResultSet.getString("whatString");
What is the error that you are receiving? Print a stack trace or something. I'm a bit confused by your post. It's impossible to connect to the database if the driver for that dbms can't be found! Something tells me you are confusing terms. Please expound.
Ok, here's the error I get: Error(16,64): cannot access class oracle.jdbc.driver.OracleDriver; file oracle\jdbc\driver\OracleDriver.class not found The error relates to the DriverManager.registerDriver instance I'm trying to create. When I try to use this code I get this error. However, I can view the database and all of it's objects when I go to the database connections window. Also, I have declare the path in my CLASSPATH file, so I'm not sure what else to do here.
Nathaniel Stoddard
Ranch Hand
Joined: May 29, 2003
Posts: 1258
posted
0
Okay -- it seems that the oracle driver isn't being added to the classpath when your IDEs run your program. I can't begin to tell you how to add these libraries to your projects so it'll be set correctly, but that's what you need to do. I know that in NetBeans, just because your driver is there and the connection shows up in the Server View, doesn't mean it will be added to the classpath and your program will run correctly.
Don't use DriverManager.registerDriver( instance ), always use Class.forName( driver name ). Theoretically they are the same, but this is not guaranteed, and Class.forName() is the recommended way to do it. In theory doing it yourself could result in the driver being reistered multiple times. Dave.
I found out what the problem was. I had to copy the needed .jar/.zip files from the Oracle lib file to the NetBeans lib file. Once I did that the connection worked fine. I didn't know there was a difference between Class.forName() and DriverManager.registerDriver(). I'll keep the Class.forName thing in mind for the future. Thanks to both of you for your input.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.