jdbc4 without class.forName
Posted by: Patryk Pa
Date: February 06, 2008 02:19PM

According to what Sun says about jdbc4 in java 6, the line Class.forName("com.mysql.jdbc.Driver"); is not needed
http://www.onjava.com/pub/a/onjava/2006/08/02/jjdbc-4-enhancements-in-java-se-6.html

But I can't make it to work, has anybody tested Connector/J 5.1.5 with Java 1.6 without it ?

String connectionString = "jdbc:mysql://localhost/db1";
String dbUser = "root";
String dbPassword = "password";
//Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection conn = DriverManager.getConnection(connectionString, dbUser, dbPassword);


The above code throws Exception No suitable driver found for jdbc:mysql://localhost/db1
I have the mysql-connector-java-5.1.5-bin.jar in Classpath beacuse when I uncomment the line Class.forName("com.mysql.jdbc.Driver"); everything works fine.

Options: ReplyQuote


Subject
Written By
Posted
jdbc4 without class.forName
February 06, 2008 02:19PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.