import java.sql.*;
import com.mysql.jdbc.jdbc2.optional.*;
import java.util.*;
import java.io.*;

public class bug11563 {

   private static final String server   = "localhost";
   private static final String database = "test";
   private static final String username = "root";
   private static final String password = "";

   private Statement stmt;

   public static void main (String [ ] args)
   {
      try
      {  System.err.println ("Initialize datasource");
         MysqlDataSource ds = new MysqlDataSource();
         ds.setServerName (server);
         ds.setDatabaseName (database);
         ds.setUser (username);
         ds.setPassword (password);
         ds.setUseNewIo (true);

         System.err.println ("Setup database connection\n");
         Connection conn = ds.getConnection();

         test (conn);
      }
      catch (Exception e)
      {  e.printStackTrace (System.err);
         System.exit (1);
      }
   }

   private static void test (Connection conn) throws Exception
   {
      Statement stmt = conn.createStatement();
      try {
         stmt.executeUpdate ("DROP TABLE IF EXISTS test");
         stmt.executeUpdate ("CREATE TABLE test (field1 integer, field2 integer)");
         stmt.executeUpdate ("INSERT INTO test (field1,field2) VALUES (NULL,NULL)");

         PreparedStatement ps = conn.prepareStatement ("SELECT * FROM test");
         ResultSet rs = ps.executeQuery();
      	if (rs.next())
      	{	Integer i = (Integer) rs.getObject ("field1");
            System.out.println ("field1: " + i);
            i = (Integer) rs.getObject ("field2");
            System.out.println ("field2: " + i + "\n");
        }
	ps.close();
      }
      finally {
         stmt.executeUpdate ("DROP TABLE IF EXISTS test");
      }
   }
}
