exception com.sql.jdbc ?

here is my code, can anyone help me wats wrong with it?

is it the driver ?

plzzz....

tnx in advance...

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

public class second {

public static void main(String args[]) {

Connection con = null;

try {

Class.forName("com.mysql.jdbc").newInstance();

con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","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) {}

}

}

}

[831 byte] By [viciousa] at [2007-11-26 19:38:00]
# 1
WHere did you place the driver jar file?
jonnyd9191a at 2007-7-9 22:15:38 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
it is "com.mysql.jdbc.Driver" not "com.mysql.jdbc".
masijade.a at 2007-7-9 22:15:38 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
ah, this is what i did....i downloaded this:mysql-connector-java-5.0.4in the mysql site, Connector/J JDBC .i put it the mysql server 5.0 folder and extracted the jar file there...
viciousa at 2007-7-9 22:15:38 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
And did you change the Driver name, like I told you. And exactly what error are you getting? In the Exception block place an e.printStackTrace method call and then provide the stacktrace.
masijade.a at 2007-7-9 22:15:39 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

I was able to connect it, just now, the problem is, wherever the com folder is ( in com.sql.jdbc.driver) it is where my java program works and able to connect to the database.....

if not, the program wont work.......

is it possible to have it work outside the "shadow" of the com folder?

here is the driver name: com.sql.jdbc.Driver

the classpath i think didnt work....?

my classpath is like this: . . . . . . c:\<the dir>\<the name of the driver.jar>

is that correct?

thanks for the help......

Message was edited by:

vicious

viciousa at 2007-7-9 22:15:39 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

How are you setting the classpath? If you use an IDE, set the jar as one of the project libraries. If not, set it using -cp on the command line. In either case do not depend on the system environment variable.

P.S. And I hope you meant "com.mysql.jdbc.Driver" and not "com.sql.jdbc.driver" as you typed.

masijade.a at 2007-7-9 22:15:39 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7
ah its com.mysql.jdbc.driver.... not .........sql........i use the environment variable, so its not reliable?thats why i said its useless.i will try the -cp on the command line...i just use notepad..........tnx.....
viciousa at 2007-7-9 22:15:39 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 8

> ah its com.mysql.jdbc.driver....

> not .........sql........

>

>

> i use the environment variable, so its not reliable?

> thats why i said its useless.

>

> i will try the -cp on the command line...

>

> i just use notepad..........

>

> tnx.....

Also note that driver should be Driver.

masijade.a at 2007-7-9 22:15:39 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...