⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buildindy.java

📁 大量java源程序
💻 JAVA
字号:
/* * @(#)BuildIndy * * Copyright (c) 1998 Karl Moss. All Rights Reserved. * * You may study, use, modify, and distribute this software for any * purpose provided that this copyright notice appears in all copies. * * This software is provided WITHOUT WARRANTY either expressed or * implied. * * @author  Karl Moss * @version 1.0 * @date    11Mar98 * */package javaservlets.db;import java.sql.*;/** * <p>This applications builds the sample Indianapolis 500 winner * database. */public class BuildIndy{  String m_tableName = "IndyWinners";  /**    * <p>Main entry point for the application    *    * The usage for the application is:    *    *   BuildIndy <driver> <URL> [<user>] [<password>]    *    * where    *   driver   = the JDBC driver class name to use (such as    *              sun.jdbc.odbc.JdbcOdbcDriver)    *   URL      = the JDBC connection URL    *   user     = the optional user name    *   password = the optional password    */  public static void main(String args[])    {      String driver = null;      String url = null;      String user = null;      String password = null;      boolean needHelp = false;      // Get the driver name      if (args.length > 0) {        driver = args[0];      }      else {        needHelp = true;      }      // Get the URL      if (args.length > 1) {        url = args[1];      }      else {        needHelp = true;      }      // Get the optional user name      if (args.length > 2) {        user = args[2];      }      // Get the optional password      if (args.length > 3) {        password = args[3];      }      // If the user needs help with the arguments, display it      if (needHelp) {        System.out.println("\nUsage: BuildIndy <driver> " +                           "<URL> [<user>] [<password>]");      }      else {        BuildIndy o = new BuildIndy();        o.build(driver, url, user, password);      }    }  /**    * <p>Build the database table    *    * @param driver JDBC driver class name    * @param url JDBC connection URL    * @param user User name    * @param password User password    */  private void build(String driver, String url,                     String user, String password)    {      java.sql.Connection con = null;      java.sql.PreparedStatement ps = null;      try {        // Attempt to create a new instance of the specified        // JDBC driver. Well behaved drivers will register        // themselves with the JDBC DriverManager when they        // are instantiated        trace("Registering " + driver);        java.sql.Driver d = (java.sql.Driver)          Class.forName(driver).newInstance();        // Create a connection to the given URL        con = java.sql.DriverManager.getConnection(url, user,                                                   password);        // Create a new helper class        SQLHelper helper = new SQLHelper(con);        // Drop the table        trace("Dropping existing " + m_tableName + " table");        helper.drop(m_tableName);        // Setup the columns        ColumnDesc cols[] = new ColumnDesc[3];        cols[0] = new ColumnDesc("Year", Types.INTEGER);        cols[1] = new ColumnDesc("Driver", Types.VARCHAR);        cols[2] = new ColumnDesc("AvgSpeed", Types.DOUBLE);        // Create the table        trace("Creating table " + m_tableName);        helper.create(m_tableName, cols);        // Add data to the table        ps = helper.prepareInsert(m_tableName, cols);        add(ps, 1997,"Arie Luyendyk",145.827);        add(ps, 1996,"Buddy Lazier",147.956);        add(ps, 1995,"Jacques Villenueve",153.616);        add(ps, 1994,"Al Unser Jr.",160.872);        add(ps, 1993,"Emerson Fittipaldi",157.207);        add(ps, 1992,"Al Unser Jr.",134.212);        add(ps, 1991,"Rick Mears",176.460);        add(ps, 1990,"Arie Luyendyk",185.984);        add(ps, 1989,"Emerson Fittipaldi",167.581);        add(ps, 1988,"Rick Mears",144.809);        add(ps, 1987,"Al Unser Sr.",162.175);        add(ps, 1986,"Bobby Rahal",170.722);        add(ps, 1985,"Danny Sullivan",152.982);        add(ps, 1984,"Rick Mears",163.612);        add(ps, 1983,"Tom Sneva",162.117);        add(ps, 1982,"Gordon Johncock",162.029);        add(ps, 1981,"Bobby Unser",139.084);        add(ps, 1980,"Jonny Rutherford",142.862);        add(ps, 1979,"Rick Mears",158.899);        add(ps, 1978,"Al Unser Sr.",161.363);        add(ps, 1977,"A.J. Foyt",161.331);        add(ps, 1976,"Jonny Rutherford",148.725);        add(ps, 1975,"Bobby Unser",149.213);        add(ps, 1974,"Jonny Rutherford",158.589);        add(ps, 1973,"Gordon Johncock",159.036);        add(ps, 1972,"Mark Donohue",162.962);        add(ps, 1971,"Al Unser Sr.",157.735);        add(ps, 1970,"Al Unser Sr.",155.749);        add(ps, 1969,"Mario Andretti",156.867);        add(ps, 1968,"Bobby Unser",152.882);        add(ps, 1967,"A.J. Foyt",151.207);        add(ps, 1966,"Graham Hill",144.317);        add(ps, 1965,"Jimmy Clark",150.686);        add(ps, 1964,"A.J. Foyt",147.350);        add(ps, 1963,"Parnelli Jones",143.187);        add(ps, 1962,"Roger Ward",140.293);        add(ps, 1961,"A.J. Foyt",139.131);        add(ps, 1960,"Jim Rathmann",138.767);        add(ps, 1959,"Roger Ward",135.857);        add(ps, 1958,"Jim Bryan",133.791);        add(ps, 1957,"Sam Hanks",135.601);        add(ps, 1956,"Pat Flaherty",128.490);        add(ps, 1955,"Bob Sweikert",128.209);        add(ps, 1954,"Bill Vukovich",130.840);        add(ps, 1953,"Bill Vukovich",128.740);        add(ps, 1952,"Troy Ruttman",128.922);        add(ps, 1951,"Lee Wallard",126.244);        add(ps, 1950,"Jonnie Parsons",124.002);        add(ps, 1949,"Bill Holland",121.327);        add(ps, 1948,"Mauri Rose",119.814);        add(ps, 1947,"Mauri Rose",116.338);        add(ps, 1946,"George Robson",114.820);        add(ps, 1945,"(no race)",0);        add(ps, 1944,"(no race)",0);        add(ps, 1943,"(no race)",0);        add(ps, 1942,"(no race)",0);        add(ps, 1941,"Floyd Davis/Mauri Rose",115.117);        add(ps, 1940,"Wilbur Shaw",115.030);        add(ps, 1939,"Wilbur Shaw",114.277);        add(ps, 1938,"Floyd Roberts",117.200);        add(ps, 1937,"Wilbur Shaw",113.580);        add(ps, 1936,"Louis Meyer",109.069);        add(ps, 1935,"Kelly Petillo",106.240);        add(ps, 1934,"William Cummings",104.863);        add(ps, 1933,"Louis Meyer",104.162);        add(ps, 1932,"Fred Frame",104.114);        add(ps, 1931,"Louis Schneider",96.629);        add(ps, 1930,"Billy Arnold",100.448);        add(ps, 1929,"Ray Keech",97.585);        add(ps, 1928,"Louis Meyer",99.482);        add(ps, 1927,"George Souders",97.545);        add(ps, 1926,"Frank Lockhart",95.904);        add(ps, 1925,"Peter DePaolo",101.127);        add(ps, 1924,"L.L Corum/Joe Boyer",98.234);        add(ps, 1923,"Tommy Milton",90.954);        add(ps, 1922,"Jimmy Murphy",94.484);        add(ps, 1921,"Tommy Milton",89.621);        add(ps, 1920,"Gaston Chevrolet",88.618);        add(ps, 1919,"Howard Wilcox",88.050);        add(ps, 1918,"(no race)",0);        add(ps, 1917,"(no race)",0);        add(ps, 1916,"Dario Resta",84.001);        add(ps, 1915,"Ralph DePalma",89.040);        add(ps, 1914,"Rene Thomas",82.474);        add(ps, 1913,"Jules Goux",75.933);        add(ps, 1912,"Joe Dawson",78.719);        add(ps, 1911,"Ray Harroun",74.602);      }      catch (Exception ex) {        ex.printStackTrace();      }      finally {        // Make sure we always clean up after ourselves        if (con != null) {          try {            ps.close();            con.close();          }          catch (Exception ex) {          }        }      }    }  /**    * <p>Helper method for adding data to the table    */  private void add(java.sql.PreparedStatement ps,                   int year, String name, double avg)    throws Exception    {      ps.setInt(1, year);      ps.setString(2, name);      ps.setDouble(3, avg);      ps.execute();     }  /**    * <p>Trace the given string    */  private void trace(String s)    {      System.out.println("BuildIndy: " + s);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -