This week's giveaway is in the Groovy forum.
We're giving away four copies of Groovy Fundamentals video training course and have Ken Kousen on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes DriverManager error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "DriverManager error" Watch "DriverManager error" New topic

DriverManager error

James White

Joined: Apr 22, 2003
Posts: 23

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:

import java.sql.*;

public class RequestSQL {

public static void main (String args[]) {

//declare connection and stament objects
Connection myConnection = null;
Statement myStatement = null;

try {

//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");

//disable auto-commit mode

//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
"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( {
id = requestResultSet.getInt("id");
no = requestResultSet.getDouble("no");
v_date = requestResultSet.getDate("v_date");
whatString = requestResultSet.getString("whatString");

System.out.println("id = " + id);
System.out.println("no = " + no);
System.out.println("v_date = " + v_date);
System.out.println("whatString = " + whatString);

//close the object

//rollback changes made to the database

} catch (SQLException e) {

System.out.println("Error code = " + e.getErrorCode());
System.out.println("Error message = " + e.getMessage());
System.out.println("SQL statement = " + e.getSQLState());
} finally {

try {

//close the Statement obj
if(myStatement != null) {

//close the connection object using the close() method
if(myConnection != null) {
} catch (SQLException e) {

Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
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.

James White

Joined: Apr 22, 2003
Posts: 23

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
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.
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

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.
James White

Joined: Apr 22, 2003
Posts: 23

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:
subject: DriverManager error