The Artima Developer Community
Sponsored Link

Java Answers Forum
jdbc driver for mysql database

4 replies on 1 page. Most recent reply: Oct 2, 2002 7:35 AM by Ana

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Ana

Posts: 12
Nickname: anika
Registered: Aug, 2002

jdbc driver for mysql database Posted: Sep 19, 2002 5:20 AM
Reply to this message Reply
Advertisement
I have a mysql database called mysql to which I?m trying to connect without success.
I have a java class called Conectar.The error message is:
Error in database java.sql.SQLException: No suitable driver
Exception in thread "main" java.lang.NullPointerException
at Conectar.main(Conectar.java:26)

The class code is:

import java.sql.*;
import java.io.*;
class Conectar{
public static void main(String [] args)
{
Connection con = null;

try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
}catch (ClassNotFoundException e){
System.err.print("ClassNotFoundException: ") ;
System.err.println(e.getMessage()) ;
return ;
}catch(IllegalAccessException iae){
}catch(InstantiationException ie){}
try{
con = DriverManager.getConnection("jdbc:mysql:mysql","","");

}
catch (SQLException e){
System.err.println("Error in database " + e);
}
finally {
try{ con.close() ;
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage()) ;
}
}
}
}


I have downloaded MySQL Connector/J 2.0.14 and installed it. All the classes are in a directory and such directory is in the classpath.
Does anybody know what?s going on?Thank you in advance.


Rajeev Mutalik

Posts: 57
Nickname: rajmutalik
Registered: Sep, 2002

Re: jdbc driver for mysql database Posted: Sep 24, 2002 2:33 AM
Reply to this message Reply
Try to download drivers from this link and try to use the data base:
http://mmmysql.sourceforge.net/oldDist.html

the version u need to downlaod is:
mm.mysql-2.0.4-bin.jar

Regards,
Rajeev
> I have a mysql database called mysql to which I?m
> trying to connect without success.
> I have a java class called Conectar.The error message
> is:
> Error in database java.sql.SQLException: No suitable
> driver
> Exception in thread "main"
> java.lang.NullPointerException
> at Conectar.main(Conectar.java:26)
>
> The class code is:
>
> import java.sql.*;
> import java.io.*;
> class Conectar{
> public static void main(String [] args)
> {
> Connection con = null;
>
> try {
>
>
>
>
>
>
>
> Class.forName("com.mysql.jdbc.Driver").newInstance();
>
> }catch (ClassNotFoundException e){
> System.err.print("ClassNotFoundException: ") ;
> : ") ;
> System.err.println(e.getMessage()) ;
> return ;
> }catch(IllegalAccessException iae){
> }catch(InstantiationException ie){}
> try{
> con =
> con =
> =
> DriverManager.getConnection("jdbc:mysql:mysql","","");
>
>
> }
> catch (SQLException e){
> System.err.println("Error in database " +
> ase " + e);
> }
> finally {
> try{ con.close() ;
> } catch(SQLException ex) {
> System.err.println("SQLException: " +
> ion: " + ex.getMessage()) ;
> }
> }
> }
> }
>
>
> I have downloaded MySQL Connector/J 2.0.14 and
> installed it. All the classes are in a directory and
> such directory is in the classpath.
> Does anybody know what?s going on?Thank you in
> advance.

Padraic R

Posts: 24
Nickname: prenagha
Registered: Sep, 2002

Re: jdbc driver for mysql database Posted: Sep 27, 2002 11:39 AM
Reply to this message Reply
Put the jar in the classpath, not the directory the jar is in.

Waihon Yew

Posts: 1
Nickname: waihon
Registered: Sep, 2002

Re: jdbc driver for mysql database Posted: Sep 30, 2002 3:54 AM
Reply to this message Reply
Try to change your getConnection statement to something like this:

conn = DriverManager.getConnection("jdbc:mysql://localhost/mysql?user=user_id&pass word=password_for_user_id");

It work on my machine. Let me know whether it works or not on yours.

> I have a mysql database called mysql to which I?m
> trying to connect without success.
> I have a java class called Conectar.The error message
> is:
> Error in database java.sql.SQLException: No suitable
> driver
> Exception in thread "main"
> java.lang.NullPointerException
> at Conectar.main(Conectar.java:26)
>
> The class code is:
>
> import java.sql.*;
> import java.io.*;
> class Conectar{
> public static void main(String [] args)
> {
> Connection con = null;
>
> try {
>
>
>
>
>
>
>
> Class.forName("com.mysql.jdbc.Driver").newInstance();
>
> }catch (ClassNotFoundException e){
> System.err.print("ClassNotFoundException: ") ;
> : ") ;
> System.err.println(e.getMessage()) ;
> return ;
> }catch(IllegalAccessException iae){
> }catch(InstantiationException ie){}
> try{
> con =
> con =
> =
> DriverManager.getConnection("jdbc:mysql:mysql","","");
>
>
> }
> catch (SQLException e){
> System.err.println("Error in database " +
> ase " + e);
> }
> finally {
> try{ con.close() ;
> } catch(SQLException ex) {
> System.err.println("SQLException: " +
> ion: " + ex.getMessage()) ;
> }
> }
> }
> }
>
>
> I have downloaded MySQL Connector/J 2.0.14 and
> installed it. All the classes are in a directory and
> such directory is in the classpath.
> Does anybody know what?s going on?Thank you in
> advance.

Ana

Posts: 12
Nickname: anika
Registered: Aug, 2002

Re: jdbc driver for mysql database Posted: Oct 2, 2002 7:35 AM
Reply to this message Reply
Thanks a lot. It has worked with the change suggested by Waihon in getConnection().

Flat View: This topic has 4 replies on 1 page
Topic: question from one student Previous Topic   Next Topic Topic: Applet Text File Database

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use