home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / VCAFE.3.0A / Sample.bin / InsertCoffees.java < prev    next >
Text File  |  1998-06-30  |  1KB  |  61 lines

  1.  
  2. import java.sql.*;
  3.      
  4. public class InsertCoffees {
  5.  
  6.     public static void main(String args[]) {
  7.           
  8.         String url = "jdbc:odbc:CoffeePot";
  9.         Connection con;
  10.         Statement stmt;
  11.         String query = "select COF_NAME, PRICE from COFFEES";
  12.     
  13.         try {
  14.             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  15.     
  16.         } catch(java.lang.ClassNotFoundException e) {
  17.             System.err.print("ClassNotFoundException: "); 
  18.             System.err.println(e.getMessage());
  19.         }
  20.  
  21.         try {
  22.  
  23.             con = DriverManager.getConnection(url, 
  24.                                      "sa", "");
  25.     
  26.             stmt = con.createStatement();                            
  27.     
  28.             stmt.executeUpdate("insert into COFFEES " +
  29.                  "values('Colombian', 00101, 7.99, 0, 0)");
  30.     
  31.             stmt.executeUpdate("insert into COFFEES " +
  32.                  "values('French_Roast', 00049, 8.99, 0, 0)");
  33.             
  34.             stmt.executeUpdate("insert into COFFEES " +
  35.                  "values('Espresso', 00150, 9.99, 0, 0)");
  36.     
  37.             stmt.executeUpdate("insert into COFFEES " +
  38.                  "values('Colombian_Decaf', 00101, 8.99, 0, 0)");
  39.     
  40.             stmt.executeUpdate("insert into COFFEES " +
  41.                  "values('French_Roast_Decaf', 00049, 9.99, 0, 0)");
  42.     
  43.             ResultSet rs = stmt.executeQuery(query);
  44.     
  45.             System.out.println("Coffee Break Coffees and Prices:");
  46.             while (rs.next()) {
  47.                 String s = rs.getString("COF_NAME");
  48.                 float f = rs.getFloat("PRICE");
  49.                 System.out.println(s + "   " + f);
  50.             }
  51.     
  52.             stmt.close();
  53.             con.close();
  54.     
  55.         } catch(SQLException ex) {
  56.             System.err.println("SQLException: " + ex.getMessage());
  57.         }
  58.     }
  59. }
  60.  
  61.