/******************************************************************** * File: http://tecfa.unige.ch/guides/java/staf2x/ex/jdbc/coffee-break/ConnectCoffeesMM.java * Made by Daniel.Schneider@tecfa.unige.ch 1/1999 TECFA. * This is Freeware * * SUN Java Tutorial JDBC Example adapted to MySQL * MM MySQL Driver Version -> http://www.worldserver.com/mm.mysql/ * At TECFA (UNIX) : source /local/env/java117.csh * setenv CLASSPATH /local/java/classes/:. * Other Sites: install the Driver * *******************************************************************/ 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://tecfa2.unige.ch:3306/COFFEEBREAK"; // 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, "nobody", null); System.out.println ("Hello, Connection to the COFFEEBREAK 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(""); } } } }