views:

117

answers:

2

Hi, I am trying to connect to mysql from java web application in eclipse.

 Connection con = null; 

  try {
    //DriverManager.registerDriver(new com.mysql.jdbc.Driver());
    Class.forName("com.mysql.jdbc.Driver");
    con = DriverManager.getConnection("jdbc:mysql://localhost/db_name","root" ,"");

    if(!con.isClosed())
      System.out.println("Successfully connected to " +
        "MySQL server using TCP/IP...");

  } catch(Exception e) {
    System.err.println("Exception: " + e.getMessage());
  } finally {
    try {
      if(con != null)
        con.close();
    } catch(SQLException e) {
     System.out.println(e.toString());
    }
  }

I am always getting the Exception: com.mysql.jdbc.Driver

I have downloaded this jar http://forums.mysql.com/read.php?39,218287,220327

import it to the "java build path/lib"

the mysql version is 5.1.3 under.

running:

mysql 5.1.3 (db is up and running queries form PHP)

windows XP

java jee

Thanks

A: 

You have to download the mysql jdbc connector und use it as lib. You can get it here:

http://www.mysql.com/downloads/connector/j/

MUG4N
tried 10 different version.... (-: not working, same exception.
fatnjazzy
+2  A: 

you say you placed the JAR on the build path, is it in the runtime class path? you said "java EE", so i assume you are deploying this as a web app? in that case you need to put the JDBC JAR file into WEB-INF/lib of your web app.

Jeff
in case of a web application the jar should be sitting in the WEB-INF and not in the build path? can you explain more?Thanks
fatnjazzy
@fatnjazzy would you read a JavaEE tutorial? It saves time.
Bozho