How to use jdbc to connect to database?
Posted by: weng zhiyi
Date: March 07, 2005 09:31PM

Hello,

I have installed MySQL4.1.9 and installed JDBC driver connect J/3.1 I installed MySQL in C:\MySQL and I have copied the "mysql-connector-java-3.1.6-bin.jar" file into <java home>\jre\lib\ext\ , <java runtime environment home>\lib\ext\ and <Tomcat Home>\ common\lib\.

I started up MySQL from the commandline client and created a 'books ' database using "CREATE DATABASE books;". I have also added the statement: GRANT ALL PRIVILEGES ON *.* TO '<user>' IDENTIFIED BY '<password>' WITH GRANT OPTION;

The problem is when I try to use java to access the database via jdbc. I typed the code:
Connection con = null;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost/books ?user=<user>&password=<password>");

It compiles correctly but when i execute the code,it displays: "SQLException: java.sql.SQLException: Incorrect database name 'books ' "

I changed the statement to:
con = DriverManager.getConnection("jdbc:mysql:books ?user=<user>&password=<password>");
but when executing,the message now is: SQLException: java.sql.SQLException: No suitable driver

I have tried checked the jdbc manuel online but the con statement given is about the same. It seems that somehow jdbc cannot find the database and the driver is not recognised also.

Is there a way to solve this? thanks

Options: ReplyQuote


Subject
Written By
Posted
How to use jdbc to connect to database?
March 07, 2005 09:31PM


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.