![]() |
|
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. |
| |||||||
| 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. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| (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 | |||
|
| Advertisements |
| | #2 | ||
| 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. | |||
|
| | #3 | ||
| 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. | |||
|
| Featured Websites | ||||
|
![]() |
| Tags: mysqlconnectorjava, sadness |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
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 | ||||
|