Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Problem with Class.forName

843854Mar 28 2004 — edited Mar 30 2004
Hello everyone!

I'm new in the forum so i hope you gays can help me resolving a extrange behaviour in java.

I have a little problem with the Class.forName() method.

I am writting a class that reads the connection parameters from a .props file so i can get the driver, url, user and password from a file and change those whitout recompiling the source files.

The problem is that i am getting an error when doing this:

try
{
Class.forName(parametros.getDriver());
con = DriverManager.getConnection(parametros.getURL(),parametros.getUser(),parametros.getPasswd());
connected = true;
}

it throws a ClassNotFoundException.

However. If i put the Strings directly it runs ok:

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:SQL","user","password");
connected = true;
}

I can't believe that. And I have searched and searched with no results.

When i tried this:

String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver);
con = DriverManager.getConnection(parametros.getURL(),parametros.getUser(),parametros.getPasswd());
connected = true;

It also throw a ClassNotFoundException.

Is the problem that Class.forName cannot take a "dinamic" parameter? It only accepts direct strings in there?? If that's so, i think that it is very limiting

I hope that you smart guys can help.

Thanxs in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 27 2004
Added on Mar 28 2004
9 comments
471 views