// Connecting to a MySQL database via JDBC

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

private Connection conn;

public void init()
   {
   // get JDBC connection to MySQL database.
   // Jar containing the Connector/J JDBC driver: mysql-connector-java-5.1.10-bin.jar must be downloaded and placed on the classpath.
   // You must configure MySQL to allow external TCP/IP connections or else localhost won't work either.

   // Instantiate the MySQL JDBC driver. Using ClassForName/newInstance
   // rather than new means the driver need not be present at compile time.
   // Oddly, we need not retain a reference to the Driver object,
   // or even do a newInstance(), just load the class.
   try
      {
      Class.forName( "com.mysql.jdbc.Driver" );
      }
   catch ( Exception e )
      {
      System.out.println( "can't load MySQL driver: " + e.getMessage() );
      }

    try
      {
      // log on to the allaboutsquirrels database
      conn = DriverManager.getConnection( "jdbc:mysql://localhost/allaboutsquirrels?user=myuserid&password=mypassword" );
      }
   catch ( SQLException e )
      {
      System.out.println( "can't connect to MySQL: " + e.getMessage() );
      }
   }
...

// create the shell into which you can pour an SQL command.
Statement stmt = conn.createStatement();