Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > MySQL Connector/J

Reply
Thread Tools

MySQL Connector/J

 
 
Claudio Penasio Junior
Guest
Posts: n/a
 
      01-05-2004
Hello all

I can't connect on MySQL whith MySQL Connector/J...

code frame...
------------------------------------------------------
String url = "jdbc:mysql://localhost:3306/banco";
String login = "blah";
String pass = "blah";
Class.forName("com.mysql.jdbc.Driver").newInstance ();
Connection con = DriverManager.getConnection(url,login,pass);

--------------------------------------------------------------

Error:
--------------------------------------------------------------
loja/BDLoja.java [31:1] unreported
exceptionjava.lang.ClassNotFoundException; must be caught or declared
to bethrownClass.forName("com.mysql.jdbc.Driver").new Instance();

------------------------------------------------------------------

I put the mysql-connector-java-3.0.9-stable-bin.jar on my CLASSPATH, i
read n times the README, and dont work. Somebody can help me?
 
Reply With Quote
 
 
 
 
Sudsy
Guest
Posts: n/a
 
      01-05-2004
Claudio Penasio Junior wrote:
> Hello all
>
> I can't connect on MySQL whith MySQL Connector/J...
>
> code frame...
> ------------------------------------------------------
> String url = "jdbc:mysql://localhost:3306/banco";
> String login = "blah";
> String pass = "blah";
> Class.forName("com.mysql.jdbc.Driver").newInstance ();
> Connection con = DriverManager.getConnection(url,login,pass);


Forget about the newInstance part. Your code should look like this:

try {
Class.forName( "com.mysql.jdbc.Driver" );
}
catch( ClassNotFoundException e ) {
System.err.println( "Could not load driver" );
}


 
Reply With Quote
 
 
 
 
newsadict
Guest
Posts: n/a
 
      01-05-2004
Hi,
It simply means you have to put your code into try-catch block.
try {
Class.forName(("com.mysql.jdbc.Driver").newInstanc e();
conn = DriverManager.getConnection(url,
user,
password);
}
catch (ClassNotFoundException exc) {
System.out.println("blah-blah");
close();
}
catch (SQLException exc) {
System.out.println("SQL-blah-blah");

close();
}
catch (Exception e) {

System.out.println("Something not Class or SQL blah-blah");
close();
}
regards
"Claudio Penasio Junior" <> wrote in message
news: om...
> Hello all
>
> I can't connect on MySQL whith MySQL Connector/J...
>
> code frame...
> ------------------------------------------------------
> String url = "jdbc:mysql://localhost:3306/banco";
> String login = "blah";
> String pass = "blah";
> Class.forName("com.mysql.jdbc.Driver").newInstance ();
> Connection con = DriverManager.getConnection(url,login,pass);
>
> --------------------------------------------------------------
>
> Error:
> --------------------------------------------------------------
> loja/BDLoja.java [31:1] unreported
> exceptionjava.lang.ClassNotFoundException; must be caught or declared
> to bethrownClass.forName("com.mysql.jdbc.Driver").new Instance();
>
> ------------------------------------------------------------------
>
> I put the mysql-connector-java-3.0.9-stable-bin.jar on my CLASSPATH, i
> read n times the README, and dont work. Somebody can help me?



 
Reply With Quote
 
Tony Morris
Guest
Posts: n/a
 
      01-06-2004
A compile error message is not intended to be a hindrance, more so,
informative. It is useful to read the information that the compiler gives
you.

"exception java.lang.ClassNotFoundException; must be caught or declared
to be thrown Class.forName("com.mysql.jdbc.Driver").newInstance ();"

This means that a checked exception called java.lang.ClassNotFoundException
must be declared to be caught or thrown when you call
Class.forName("com.blah").newInstance();

If you don't understand what this means, I strongly suggest that you learn
the fundamentals of exception handling in Java before using JDBC:

http://java.sun.com/docs/books/tutor...al/exceptions/

Good luck.

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software


"Claudio Penasio Junior" <> wrote in message
news: om...
> Hello all
>
> I can't connect on MySQL whith MySQL Connector/J...
>
> code frame...
> ------------------------------------------------------
> String url = "jdbc:mysql://localhost:3306/banco";
> String login = "blah";
> String pass = "blah";
> Class.forName("com.mysql.jdbc.Driver").newInstance ();
> Connection con = DriverManager.getConnection(url,login,pass);
>
> --------------------------------------------------------------
>
> Error:
> --------------------------------------------------------------
> loja/BDLoja.java [31:1] unreported
> exceptionjava.lang.ClassNotFoundException; must be caught or declared
> to bethrownClass.forName("com.mysql.jdbc.Driver").new Instance();
>
> ------------------------------------------------------------------
>
> I put the mysql-connector-java-3.0.9-stable-bin.jar on my CLASSPATH, i
> read n times the README, and dont work. Somebody can help me?



 
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
Re: How to insert PDF file in to MySql and read it from MySql toJAVA App Jeffrey H. Coffield Java 1 07-24-2009 12:29 AM
MySQL-python-1.2.2 install with no mysql washakie Python 4 01-15-2008 08:15 PM
"mysql.h: No such file or directory" when building MySQL-python francescomoi@europe.com Python 2 05-11-2005 03:12 PM
DBD:mysql doesn't read mysql option file /etc/my.cnf file JL Perl 0 01-28-2005 03:19 AM
"Pure Python" MySQL module like Net::MySQL Ravi Python 6 07-21-2003 06:53 PM



Advertisments