File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes mysql driver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "mysql driver" Watch "mysql driver" New topic
Author

mysql driver

pree sree
Ranch Hand

Joined: Jul 27, 2002
Posts: 34
MySQL Driver is at - C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\struts-blank\WEB-INF\lib\mysql-connector-java-3.1.12-bin.jar .

When i am running my java class in eclipse i am getting

java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver

I don't know what has gone wrong.

This is the connection part from my code.

Class.forName("org.gjt.mm.mysql.Driver");
String database = "jdbc:mysql:C:/Program Files/MySQL/MySQL Server 5.0/data/test";
Connection con = DriverManager.getConnection(database,"","");

Please help me.
[ March 31, 2006: Message edited by: pree sree ]
Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 263
hello pree sree
I'ven't use the MySql database before!!
i think so like this

u just try like this

String database = "jdbcdbc:localhost:<portno>:<database_name>"
ie., egs :
String database = jdbcdbc:localhost:1521racle"
Connection con = DriverManager.getConnection(database,"scott","tiger");

this will work in oracle!!
check out the port for mysql server.. and .. try it out!!

thank you

regards!!
Aravind Prasad
[ April 01, 2006: Message edited by: Marilyn de Queiroz ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Aravind is recommending you use the JDBC-ODBC bridge. I strongly recommend that you do not.

You are trying to connect to the MySQL file for some reason. MySQL runs as a server, and you have to connect to it as such. Therefore your Database url will look similar to this:
String database="jdbc:mysql://localhost:test";

See the JDBC url info here.

Dave
pree sree
Ranch Hand

Joined: Jul 27, 2002
Posts: 34
I have my mysql database in C:\Program Files\MySQL\MySQL Server 5.0\data

how can i put it in my webapp directory?
[ April 01, 2006: Message edited by: pree sree ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

But this is a database server, that you should be refering to, not a file. When you talk to a web app, you need to get the browser to talk to the server even if that server is running on the local computer, Sure, you could access the files directly, but it wouldn't work.

Same with MySQL. This is not MSAccess. You can get to an Access DB directly via the file, but this is because Access is not designed for large scalable systems like other Databases are.

SO you need to make sure the MySQL database server is running and then connect using the url I gave above.

I did get distracted from you original error, which is "ClassNotFound". It looks like you're using the wrong classname foir that driver, try "com.mysql.jdbc.Driver"

Dave
pree sree
Ranch Hand

Joined: Jul 27, 2002
Posts: 34
Class.forName("org.gjt.mm.mysql.Driver") ;-------A
String database = "jdbc:mysql://localhost:test";
Connection con = DriverManager.getConnection(database,"",""); ----------B

I am sorry but i am getting the following error at line B even when i used "com.mysql.jdbc.Driver" in line A

java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at conn.getConnection(conn.java:30) ----------B
at conn.update(conn.java:69)
at conn.main(conn.java:96)
Exception in thread "main" java.lang.NullPointerException
at conn.update(conn.java:75)
at conn.main(conn.java:96)

i really appreciate ur help.
[ April 01, 2006: Message edited by: pree sree ]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

"jdbc:mysql://localhost:test"
No. Read the page that was linked to more carefully. The database name comes after a slash, not after a colon. So thus:
"jdbc:mysql://localhost/test"
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Thanks Paul, my bad
pree sree
Ranch Hand

Joined: Jul 27, 2002
Posts: 34
I got 'the connection' .Thanks everyone for the help given and a special thanks to David!
 
wood burning stoves
 
subject: mysql driver