Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2003
    Location
    germany
    Posts
    17

    Unanswered: java-pgm to mysql with MySQL ODBC 3.51

    hello,

    i try to access a mysql -database with a java-programm
    (Win 2000 Professional).

    I have installed MySQL ODBC 3.51 Driver from mysql.com

    The Java-Source-Code :

    import java.sql.*;
    public class DataBaseDemo
    {
    public static void main(String args[])
    {
    String name, address, phone;
    int ssNo;

    String url = "jdbcdbc:javas";

    String sqlQuery = "Select name, ssno,address
    phone from customer";

    try
    {
    Class.forName("myodbc3-test");
    Connection aConnection =
    DriverManager.getConnection(url,
    "myname", "mypassword");

    Statement aStatement =
    Connection.createStatement();

    ResultSet rs =
    aStatement.executeQuery(sqlQuery);

    // get first row
    boolean more = rs.next();
    while (more)
    {
    name = rs.getString(1);
    ssNo = rs.getInt(2);
    address = rs.getString(3);
    phone = rs.getString(4);

    System.out.println("Name: " + name);
    System.out.println("ssNo: " + ssNo);
    System.out.println("address: " + address);
    System.out.println("phone: " + phone);

    more = rs.next();
    }

    rs.close();
    aStatement.close();
    aConnection.close();
    }

    catch (ClassNotFoundException e)
    {
    System.out.println("Exception caught " + e);
    }
    catch (SQLException e)
    {
    while (e != null)
    {
    System.out.println("SQLExeption caught " +e);
    e = e.getNextException();
    }
    }
    }

    }


    I get the program compiled. But when executing i get
    the following error:

    Exception.caught java.lang. ClassNotFoundException:
    myodbc3-test (which is is the Data Source Name in ODBC)

    I think there is an error inClass.ForName but I am not sure.

    thanks a lot for help
    chris

  2. #2
    Join Date
    Dec 2003
    Posts
    1

    My sql odbc

    chris
    u should write
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    iam not sure u got the answer any way

    bye

  3. #3
    Join Date
    Mar 2003
    Location
    germany
    Posts
    17

    Mysql odbc

    thanks for your replay

    but i got a solution by myself (try and error)

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
    doesn't work. This driver isn't installed.
    I did the following:


    i replaced the string url to "jdbc:mysql:///javas"
    ---- javas is the database name

    and class.forName to
    Class.forName("com.mysql.jdbc.Driver")

    There seems to be different solutions ?!
    i have created a user-dsn in the odbc-panel
    based on MySQl ODBC 3.51. Also there is
    the com.mysql.jdbc.Driver but on an different
    directory than the java-programs. But this
    driver seems not to be necessary. If i rename
    it the programm still works.

    Any idea ?
    thanks
    chris

Posting Permissions

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