JDBC

ODBC

JDBC

Example MySQL connection

This uses the MM JDBC driver for mySql

import java.sql.*;

public class Jdbc {

    public static void main(String[] Args) {
       try {
           // The newInstance() call is a work around for some
           // broken Java implementations
           Class.forName("org.gjt.mm.mysql.Driver").newInstance();
       } catch (Exception E) {
           System.err.println("Unable to load driver.");
           E.printStackTrace();
       }
       try {
           Connection myConn =
                DriverManager.getConnection(
                   "jdbc:mysql://marigold.ise.canberra.edu.au/test");
       } catch(Exception e) {
           System.err.println("failed to connect");
           e.printStackTrace();
       }
       Statement statement = connection.createStatement();
       String sql = "INSERT INTO ...";
       statement.executeQuery(sql);
       statement.close();
    }
}

Running mySql


Jan Newmarch (http://pandonia.canberra.edu.au)
jan@ise.canberra.edu.au
Last modified: Tue Oct 10 15:27:39 EST 2000
Copyright ©Jan Newmarch