Solved

getting a start at jdbc mysql

Posted on 2000-04-13
4
326 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumHeights2  challenge 7 78
Issues installing SSL certificate into Apache Tomcat 3 70
firstChar challenge 13 86
Java and GPO 11 47
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

744 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

13 Experts available now in Live!

Get 1:1 Help Now