mysql-connector-java sadness

This is a discussion on mysql-connector-java sadness within the MySQL Database forums, part of the Database Forums category; (Question at bottom) OS: FreeBSD 6.0 using the ports collection to install jdk14 # pkg_info | grep jdk jdk-1.4....


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-05-2006
Walter Vaughan
 
Posts: n/a
Default mysql-connector-java sadness

(Question at bottom)

OS: FreeBSD 6.0 using the ports collection to install jdk14
# pkg_info | grep jdk
jdk-1.4.2p8_3 Java Development Kit 1.4.2
linux-sun-jdk-1.4.2.11 Sun Java Development Kit 1.4 for Linux

I am trying to use ofbiz with MySQL rather than Derby. I am pretty sure that the
failure is in how jdbc works with MySQL, so I found what I thought would be an
example that would test my setup. I found this code and followed the directions
to run it...

[CODE ...]
package com.stardeveloper.example;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JdbcExample2 {

public static void main(String args[]) {
Connection con = null;

try {
Class.forName("com.mysql.jdbc.Driver").newInstance ();
con = DriverManager.getConnection("jdbc:mysql://localhost/ofbiz", "user",
"password");

if(!con.isClosed())
System.out.println("Successfully connected to " +
"MySQL server using TCP/IP...");

} catch(Exception e) {
System.err.println("Exception: " + e.getMessage());
} finally {
try {
if(con != null)
con.close();
} catch(SQLException e) {}
}
}
}
[END_CODE... ]

After compiling, (inserting correct login/password) I run it and get...
# java com.stardeveloper.example.JdbcExample2
Exception: com.mysql.jdbc.Driver

Which seemed to be the same error that "ofbiz" was telling me. I think the java
install is okay, since the application runs fine using the Derby database.

# pkg_info | grep mysql
mysql-client-5.0.20 Multithreaded SQL database (client)
mysql-connector-java-3.1.12 MySQL Connector/J: JDBC interface for MySQL
mysql-server-5.0.20 Multithreaded SQL database (server)

I know MySQL is running fine since I can dink around with it with webmin.

GETTING TO THE QUESTION(s)...
Does anyone have a code snippet that they could share that uses jdbc and mysql
that they could share that they know would work as a "hello world" to prove to
me that I have things configured fine, and just a 1,2,3 proceedure list to make
sure I even am creating the class file okay and am running the way it was intended?

If this is not the correct newsgroup, does anyone have an idea where one would
have mysql-connector-java experts?

--
Walter
Reply With Quote
  #2 (permalink)  
Old 05-05-2006
Bill Karwin
 
Posts: n/a
Default Re: mysql-connector-java sadness

Walter Vaughan wrote:
> After compiling, (inserting correct login/password) I run it and get...
> # java com.stardeveloper.example.JdbcExample2
> Exception: com.mysql.jdbc.Driver


What type of exception is it? I'm guessing it's a
ClassNotFoundException, caused by your MySQL connector jar not being
found on the CLASSPATH.

This illustrates the problem with "catch (Exception)" -- it obscures the
root cause of the exception. It's better to use a series of "catch
(SQLException)", "catch (ClassNotFoundException)", etc. Basically one
catch block for each exception type that might be thrown in your try
block. That way, you can report and respond to the different types of
exceptions more appropriately.

Or you could take a shortcut and print out the error as follows:
System.err.println(e.getClass().getName() + .getMessage());

Regards,
Bill K.
Reply With Quote
  #3 (permalink)  
Old 05-05-2006
Bill Karwin
 
Posts: n/a
Default Re: mysql-connector-java sadness

Bill Karwin wrote:
> System.err.println(e.getClass().getName() + .getMessage());


I missed an e there.

System.err.println(e.getClass().getName() + e.getMessage());

Regards,
Bill K.
Reply With Quote
  #4 (permalink)  
Old 05-11-2006
TestMan
 
Posts: n/a
Default Re: mysql-connector-java sadness

Hi Walter,
JDBC works great for lots of people with MySQL ;-)

Start accessing your database with :
http://squirrel-sql.sourceforge.net/

Adding the JAR of the mysql-...-bin.jar to the extra class path tab of
the MySQL Driver entry.
The simply put your URL and login password and enjoy :)

Always usefull to have a second test with an wrking program to find out
where is the problem.

IMHO, the only problem you can be confronted on JDBC is to forget about
putting the JAR in a classpath ;-)

Rgs,
TM

Walter Vaughan a écrit :
> (Question at bottom)
>
> OS: FreeBSD 6.0 using the ports collection to install jdk14
> # pkg_info | grep jdk
> jdk-1.4.2p8_3 Java Development Kit 1.4.2
> linux-sun-jdk-1.4.2.11 Sun Java Development Kit 1.4 for Linux
>
> I am trying to use ofbiz with MySQL rather than Derby. I am pretty sure
> that the failure is in how jdbc works with MySQL, so I found what I
> thought would be an example that would test my setup. I found this code
> and followed the directions to run it...
>
> [CODE ...]
> package com.stardeveloper.example;
>
> import java.sql.Connection;
> import java.sql.DriverManager;
> import java.sql.SQLException;
>
> public class JdbcExample2 {
>
> public static void main(String args[]) {
> Connection con = null;
>
> try {
> Class.forName("com.mysql.jdbc.Driver").newInstance ();
> con = DriverManager.getConnection("jdbc:mysql://localhost/ofbiz",
> "user",
> "password");
>
> if(!con.isClosed())
> System.out.println("Successfully connected to " +
> "MySQL server using TCP/IP...");
>
> } catch(Exception e) {
> System.err.println("Exception: " + e.getMessage());
> } finally {
> try {
> if(con != null)
> con.close();
> } catch(SQLException e) {}
> }
> }
> }
> [END_CODE... ]
>
> After compiling, (inserting correct login/password) I run it and get...
> # java com.stardeveloper.example.JdbcExample2
> Exception: com.mysql.jdbc.Driver
>
> Which seemed to be the same error that "ofbiz" was telling me. I think
> the java install is okay, since the application runs fine using the
> Derby database.
>
> # pkg_info | grep mysql
> mysql-client-5.0.20 Multithreaded SQL database (client)
> mysql-connector-java-3.1.12 MySQL Connector/J: JDBC interface for MySQL
> mysql-server-5.0.20 Multithreaded SQL database (server)
>
> I know MySQL is running fine since I can dink around with it with webmin.
>
> GETTING TO THE QUESTION(s)...
> Does anyone have a code snippet that they could share that uses jdbc and
> mysql that they could share that they know would work as a "hello world"
> to prove to me that I have things configured fine, and just a 1,2,3
> proceedure list to make sure I even am creating the class file okay and
> am running the way it was intended?
>
> If this is not the correct newsgroup, does anyone have an idea where one
> would have mysql-connector-java experts?
>
> --
> Walter

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:06 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0