Professional Web Applications Themes

mysql-connector-java sadness - MySQL

(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 ...

  1. #1

    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
    Walter Vaughan Guest

  2. #2

    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.
    Bill Karwin Guest

  3. #3

    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.
    Bill Karwin Guest

  4. #4

    Default Re: mysql-connector-java sadness

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

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

    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
    TestMan Guest

Similar Threads

  1. #40085 [NEW]: PHP/MySQL connector and Stored Procedure problem
    By edward_chan at hotmail dot com in forum PHP Bugs
    Replies: 2
    Last Post: January 10th, 07:52 AM
  2. MySQL Connector/J - driver not recognised
    By erasmus in forum Coldfusion Server Administration
    Replies: 1
    Last Post: October 22nd, 01:49 PM
  3. How do I connect with MySQL Connector/NET 1.0
    By Gerrit de Haan in forum MySQL
    Replies: 4
    Last Post: June 9th, 08:43 AM
  4. Help! MySQL Connector/J too slow for production use!
    By shirai in forum Coldfusion Database Access
    Replies: 1
    Last Post: March 13th, 01:24 PM
  5. MySQL 4.1 & CFMX 6.1 connector problems
    By Babray in forum Coldfusion Database Access
    Replies: 13
    Last Post: September 29th, 12:17 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139