On my system I added the classpath to my mm.mysql installation directory or
/usr/local/mm.mysql.jdbc-1.2c  This was enough to give me access to my
database.

Here is some sample code that you can modify to retrive data from your
database.

import java.sql.*;
import java.io.*;

public class newjavadb
{

        public static void main( String [ ] args )
        {
                String username = "avaliduser";
                String password = "avalidpwd";
                String url = "jdbc:mysql://domain.com.au/databasename";
                String queryString = "SELECT ves_ref FROM
lbs_web_ves_sched";
                int count = 0;
                // Load the driver
                try
                {

Class.forName("org.gjt.mm.mysql.Driver").newInstance();
                        System.out.println("Success Driver Loaded" );
                }
                catch(java.lang.ClassNotFoundException e)
                {
                        System.err.print("ClassNotFoundException: ");
                        System.err.println( e.getMessage() );
                }
                catch( Exception e )
                {
                        System.err.print("Exception : " + e );
                }

                try
                {
                        System.out.println("Inside Connection Try block" );
                        Connection con;
                        Statement stmt;
                        System.out.println("url is :" + url );

                        // Establish connection to the database
                        con = DriverManager.getConnection(url, username,
password);
                        System.out.println("Ok, connection to the DB
worked.");
                        System.out.println("Let's see can retrieve something
with : " +
                                        queryString );

                        // Create a Statement object
                        stmt = con.createStatement();
                        // Send the query and bind the result to a set
                        ResultSet rs = stmt.executeQuery(queryString);
                        while( rs.next() )
                        {
                                count++;
                                String s = rs.getString("ves_ref");
                                System.out.println( s + "is the FIELD value.
Count is:" + count );
                        }

                        // Close resources
                        stmt.close();
                        con.close();
                }// end try block
                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(" ");
                        }
                }// end catch block
        }// end main
}// end class newjavadb


----- Original Message -----
From: Shailaja Someshwar <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, December 28, 2000 10:27 PM
Subject: mm JDBC driver


> Hello
>
> Where do I need to place the mm.jdbc driver for MySQL
> in tomcat directory so that its available system wide
> and all of the Apache virtual hosts.
>
> Also can someone direct me to a sample application to
> test my JDBC connection is working or not, as I do not
> know much about Java.
>
> Thanks in advance.
>
> Regards,
> Shailaja
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Photos - Share your holiday photos online!
> http://photos.yahoo.com/

Reply via email to