List:MySQL and Java« Previous MessageNext Message »
From:Eric Eldred Date:March 27 1999 3:31am
Subject:Re: mm jdbc on win95
View as plain text  
/**
*thanks for the hints!  just in case anyone feels like
*developing a faq, this ought to be added.  code follows
and the experts here can tune it up better than me:
/*

/** Simple - test mysql connection with mm jdbc driver
* @args - none
* jdk1.17b on win95 with mysql - won't work under jdk1.2 with mm
driver
* install org/gjt/mm/mysql/* under jdk home
* set CLASSPATH=
*/
import org.gjt.mm.mysql.*;
//also import following packages separately:
import org.gjt.mm.mysql.Connection;
//if you use a Statement in your code add this:
//import org.gjt.mm.mysql.Statement;
import org.gjt.mm.mysql.Driver;
import java.sql.*;
// in case you use the Properties part, commented out here:
//import java.util.Properties;

public class Simple
{
static public void main(String args[])
{
// this Connection is from java.sql.Connection
                Connection conn = null;
        try
// use .newInstance(); per the README file
        {      
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
        }
        catch (Exception e)
        {
                System.out.println("driver failure");
                e.printStackTrace();
                return;
        }
// following may be needed for some applets(?) -- see mm's README
/*      Properties P = System.getProperties();
        P.put("jdbc.drivers", "org.gjt.mm.mysql.Driver");
        System.setProperties(P);
*/
        try
/** NOTE: use the "?user=" syntax instead of another string arg to
getConnection
* use the semicolon before 'password' instead of the '&', at least
for win32
* you MUST supply the user and password strings -- don't leave out
* use 3306 as port, though it may be default
* 'test' is the database name
* first set up 'monty' or whoever with mysql privileges, username,
and password and
* be sure to do a 'mysqladmin reload' afterwards - see mysql manual
*/
        {       String url =
"jdbc:mysql://localhost:3306/test/?user=monty;password=''";    
// don't forget to cast with (Connection) back to
java.sql.Connection type
                conn = (Connection)
DriverManager.getConnection(url);
                System.out.println("Connection successful");
        }
        catch (SQLException e)
        {       System.out.println("Connection failed");
                e.printStackTrace();
        }
        finally
        {       try
                {       conn.close();
                        System.out.println("Connection closed");
                }
                catch (Exception e)
                {       System.out.println("Connection exception");
                        e.printStackTrace();
                }
        }
}
}

/**
-- 
"Eric"    Eric Eldred      Eldritch Press
mailto:EricEldred@stripped  http://eldred.ne.mediaone.net/
"support online books!" http://eldred.ne.mediaone.net/support.html
*/
Thread
Re: mm jdbc on win95Eric Eldred28 Mar
  • Re: mm jdbc on win95mmatthew28 Mar