// Added by Nathan Folkert: /*********************************************************************** ** ** File: /afs/ir/users/c/j/cjurney/public/cs145/SQLRunner.java ** ** Author: Craig Jurney, ITSS ** ** Written: April, 2000 ** ** Classes: SQLRunner ** ** Description: Simple template class used for executing a SQL query. ** ** Maintenance: ** 04/10/00 cjurney Initial version ** **---------------------------------------------------------------------- ** Copyright (c) 2000 Board of Trustees, Leland Stanford Jr. University ************************************************************************/ import java.sql.*; public class MySQLRunner { public static String USERNAME = new String("scott"); public static String PASSWORD = new String("tiger"); public static String ADDRESS = "jdbc:mysql://pc236nt.napier.ac.uk/gisq"; public static void main(String[] args) throws ClassNotFoundException { // Load the Oracle Driver Class.forName("com.mysql.jdbc.Driver"); try { // Get a connection from the connection factory Connection con = DriverManager.getConnection(ADDRESS, USERNAME, PASSWORD); // Show some database/driver metadata SQLUtil.printDriverInfo(con); // Create a Statement object so we can submit SQL statements to the driver Statement stmt = con.createStatement(); // Submit a query, creating a ResultSet object ResultSet rs = stmt.executeQuery(args[0]); // Display all columns and rows from the result set SQLUtil.displayResultSet(rs); // Close the result set rs.close(); // Close the statement stmt.close(); // Close the connection con.close(); } catch (java.lang.ArrayIndexOutOfBoundsException ae) { System.out.println("USAGE: java SQLRunner "); } catch (SQLException e) { SQLUtil.printSQLExceptions(e); } } }