Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > jdbc connect to mysql database

Reply
Thread Tools

jdbc connect to mysql database

 
 
Marcus Krieger
Guest
Posts: n/a
 
      12-10-2004
I am using JBuilder and I would like to connect to a mysql database.
I was able to connect to a oracle database, however it does not work with
mysql!
I downloaded the newest drivers from the mysql webseite and put them into my
java/bin directory.
As I don't know exactly which java folder Jbuilder is using I have put them
in both folder - my java folder and the java folder in jbuilder.
Additionally, I tried to import the file from Jbuilder, and put them into
"Project", "User Home" and "Jbuilder".

Whatever that exactly does, with oracle it had worked.
Using mysql, I get the following error message:

driver:com.mysql.jdbc.Driver url:jdbc:mysql:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
java.sql.SQLException: No suitable driver
java.sql.SQLException: No suitable driver

That's my code:
[..]
jdbc_driver="com.mysql.jdbc.Driver";
db_login = "root";
db_password = "";
db_url = "jdbc:mysql://localhost:3306/dbname";
try
{
Class.forName(jdbc_driver);
}
[..]
DriverManager.getConnection(db_url, db_login, db_password);

Any ideas, what I am doing wrong here?

Thanks,

Marcus



 
Reply With Quote
 
 
 
 
Collin VanDyck
Guest
Posts: n/a
 
      12-10-2004
Marcus Krieger wrote:
> driver:com.mysql.jdbc.Driver url:jdbc:mysql:
> java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
> java.sql.SQLException: No suitable driver
> java.sql.SQLException: No suitable driver


Most likely the connector jar is not on your classpath. If you cannot
figure out where to place it, it SHOULD work if you place it in your
%SYSTEM_JRE%/lib/endorsed directory.
 
Reply With Quote
 
 
 
 
Ian T
Guest
Posts: n/a
 
      12-11-2004
Marcus Krieger wrote:

If you Read the first page of The Fine Documentation that comes with the
official jdbc driver (www.mysql.com), you will find a code example that
will work immediately. My java implementation would only work with the
newInstance code below.

Something like:

try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance ();
}
catch (Exception ex) { // handle the error }
java.sql.Connection c =
DriverManager.getConnection("jdbc:mysql://localhost/recruitment?user=root&password=");
java.sql.ResultSet r = s.executeQuery("SELECT * FROM Candidates");
while ( r.next())
{
System.out.println(r.getString("fullname"));
System.out.println(r.getString("phone"));
}
s.close();
c.close();


Ian

> I am using JBuilder and I would like to connect to a mysql database.
> I was able to connect to a oracle database, however it does not work with
> mysql!
> I downloaded the newest drivers from the mysql webseite and put them into my
> java/bin directory.
> As I don't know exactly which java folder Jbuilder is using I have put them
> in both folder - my java folder and the java folder in jbuilder.
> Additionally, I tried to import the file from Jbuilder, and put them into
> "Project", "User Home" and "Jbuilder".
>
> Whatever that exactly does, with oracle it had worked.
> Using mysql, I get the following error message:
>
> driver:com.mysql.jdbc.Driver url:jdbc:mysql:
> java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
> java.sql.SQLException: No suitable driver
> java.sql.SQLException: No suitable driver
>
> That's my code:
> [..]
> jdbc_driver="com.mysql.jdbc.Driver";
> db_login = "root";
> db_password = "";
> db_url = "jdbc:mysql://localhost:3306/dbname";
> try
> {
> Class.forName(jdbc_driver);
> }
> [..]
> DriverManager.getConnection(db_url, db_login, db_password);
>
> Any ideas, what I am doing wrong here?
>
> Thanks,
>
> Marcus
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
Is there any way to connect database without JDBC? kevin Liu Java 19 10-07-2008 10:50 AM
How to connect Java application with Oracle Database using JDBC? dilip Java 4 09-28-2007 04:02 PM
JDBC Mysql Connect Problem Chow Java 2 12-15-2003 02:46 PM



Advertisments