Link to home
Start Free TrialLog in
Avatar of thedogeater
thedogeater

asked on

getting a start at jdbc mysql

I am useing jdk1.1.8
and mm.mysql.jdbc-1.2c

I want to this code

import java.sql.*;

public class ConnectCoffeesMM {
    public static void main(String args[]) {

        // The URL that will connect to TECFA's MySQL server
        // Syntax: jdbc:TYPE:machine:port/DB_NAME
        String url = "jdbc:mysql://serka.sawbos.jive:3306/CD";

        // INSTALL/load the Driver (Vendor specific Code)
        try {
            Class.forName("org.gjt.mm.mysql.Driver");

        } catch(java.lang.ClassNotFoundException e) {
            System.err.print("ClassNotFoundException: ");
            System.err.println(e.getMessage());
        }

        try {
            Connection con;
            Statement stmt;
           
            // Establish Connection to the database at URL with usename and password
            con = DriverManager.getConnection(url, "root", "*******");
            System.out.println ("Hello, Connection to the CD table worked");
            con.close();

        } catch(SQLException ex) {
            System.err.println("==> SQLException: ");
              while (ex != null) {
                  System.out.println("Message:   " + ex.getMessage ());
                  System.out.println("SQLState:  " + ex.getSQLState ());
                  System.out.println("ErrorCode: " + ex.getErrorCode ());
                  ex = ex.getNextException();
                  System.out.println("");
              }
        }
    }
}

all goes well with javac
but java ConnectCoffeesMM gives me
ClassNotFoundException: org.gjt.mm.mysql.Driver
==> SQLException:
Message:   No suitable driver
SQLState:  08001
ErrorCode: 0


So I have not got it my CLASSPATH
but setevn CLASSPATH /usr/local/mm.mysql.jdbc-1.2c:$CLASSPATH
gets me nothing, now I am told
Can't find class ConnectCoffeesMM
so the $CLASSPATH must be wrong what shoud it be?? I am baffeled

Thanks for any help.
ASKER CERTIFIED SOLUTION
Avatar of fmaritato
fmaritato

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of terajiv
terajiv

Make Sure that Proper Driver is Loaded on your System. Then try running the Application...

And Ofcourse Classpath is also Important.

All the Best

Rajiv
Avatar of thedogeater

ASKER

Thans for teh responces I got it to work in the end
fmaritato was right about the CLASSPATH
but the one he or she gave did not work
anyhow  Iwill give teh points.
hi thedogeater,

i have same problem as you,

ClassNotFoundException: com/imaginary/sql/msql/MsqlDriver
==> SQLException:
Message:   driver not found: jdbc:mysql://www.hketutor.com/hketutor
SQLState:  null
ErrorCode: 0


how can you solve your problem?
can you explain it in details to me?
i can give you 100 points.