/******************************************************************** * File: http://tecfa.unige.ch/guides/java/staf2x/ex/jdbc/coffee-break/ConnectCoffeesTwz1.java * Made by Daniel.Schneider@tecfa.unige.ch 1/1999 TECFA. * This is Freeware * * SUN Java Tutorial JDBC Example adapted to MySQL * Twz1 MySQL Driver Version -> http://www.voicenet.com/~zellert/tjFM/ * At TECFA (UNIX) : source /local/env/java117.csh * setenv CLASSPATH /local/java/classes/:. * Other Sites: install the Driver * *******************************************************************/ import twz1.jdbc.mysql.*; import java.sql.*; public class ConnectCoffeesTwz1 { 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:z1MySQL://tecfa.unige.ch:3306/COFFEEBREAK"; // INSTALL/load the Driver (Vendor specific Code) try { Class.forName("twz1.jdbc.mysql.jdbcMysqlDriver"); } 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 = (Connection) 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(""); } } } }