// 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 SQLRunner { public static String USERNAME = new String("yourname"); public static String PASSWORD = new String("yourpasswd"); public static void main(String[] args) throws ClassNotFoundException { // Load the Oracle Driver Class.forName("oracle.jdbc.driver.OracleDriver"); try { // Get a connection from the connection factory Connection con = DriverManager.getConnection( "jdbc:oracle:thin:@dbaprod1:1521:SHR1_PRD", 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 (SQLException e) { SQLUtil.printSQLExceptions(e); } } }