View Single Post
  #1 (permalink)  
Old 02-03-2008, 01:01 AM
prfalco prfalco is offline
Member
 
Join Date: Jan 2008
Posts: 7
prfalco is on a distinguished road
can't register a MySQL driver
Hello:
I have this code to connect to a MySQL database:

package paquetedb;

import java.sql.*;

public class PruebaDB {

public static void main(String[] args) {
Connection con = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance ();
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","xyz001");
if (!con.isClosed()){
System.out.println("conexión exitosa a MySQL");
}
}catch(Exception e){
System.err.println("Excepción: " + e.getMessage());
}finally{
try{
if (con != null)
con.close();
} catch(SQLException e){}
}
}

}

When it gets to "Class.forName("com.mysql.jdbc.Driver").newInstanc e();"
it always gets to the catch(exception e) indicating that there's something wrong when trying to load the driver.
I'm using NetBeans 6.0 and in the services tab, I connect to the database without any problem, indicating that my database server is running ok.
I've been looking around in the net and seems everyone is writing the some code to do this task.
What could be the problem?
Thank you.
Reply With Quote
Sponsored Links