Problem with Class.forName
843854Mar 28 2004 — edited Mar 30 2004Hello 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