Computer Webmaster Gaming Console Graphics Forum

Welcome to the Computer Webmaster Gaming Console Graphics Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > Database
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases.

Google
Reply
 
LinkBack Thread Tools Display Modes
Old 07-01-2007, 9:33 PM   #1
Walter Vaughan
 
Walter Vaughan's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

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
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Advertisements
Old 07-01-2007, 9:33 PM   #2
Bill Karwin
 
Bill Karwin's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default 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.
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 07-01-2007, 9:33 PM   #3
Bill Karwin
 
Bill Karwin's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default 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.
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Featured Websites
Free Space
Free Space
Free Space Free Space
Reply
Tags: ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL Connector .NET 1.0.6 and "Connection unexpectedly terminated" exception Sven Jacobs Database 3 11-07-2008 5:53 PM
Java: MySQL DATETIME conversion errors? Cédric Pillonel Database 3 07-01-2007 7:32 PM
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) Cteodor Database 0 07-01-2007 6:43 PM
MySQL Connector .NET 1.0.6 and "Connection unexpectedly terminated" exception Sven Jacobs Database 1 07-01-2007 6:25 PM
Connector Pinouts Pete Car audio 4 06-18-2007 12:27 PM


Featured Websites




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


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98