Solved

getting a start at jdbc mysql

Posted on 2000-04-13
4
327 Views
Last Modified: 2012-06-27
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.
0
Comment
Question by:thedogeater
4 Comments
 
LVL 1

Accepted Solution

by:
fmaritato earned 100 total points
ID: 2714142
you have to put the location of the jar file in your classpath:

setenv CLASSPATH /usr/local/mm.mysql.jdbc/mysql_comp.jar:${CLASSPATH}

0
 
LVL 3

Expert Comment

by:terajiv
ID: 2714732
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
0
 

Author Comment

by:thedogeater
ID: 2719515
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.
0
 

Expert Comment

by:stanleyhuen
ID: 3399371
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 98
Java array passed to SQL where clause 23 61
GUI builder for Eclipse? 8 27
custom annotations 9 29
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now