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

  1.  
  2. import java.sql.*;
  3.      
  4. public class InsertSuppliers {
  5.  
  6.     public static void main(String args[]) {
  7.           
  8.         String url = "jdbc:odbc:CafeJava";
  9.         Connection con;
  10.         Statement stmt;
  11.         String query = "select SUP_NAME, SUP_ID from SUPPLIERS";
  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.             con = DriverManager.getConnection(url, 
  23.                                      "Admin", "duke1");
  24.     
  25.             stmt = con.createStatement();                            
  26.     
  27.             stmt.executeUpdate("insert into SUPPLIERS " +
  28.                      "values(49, 'Superior Coffee', '1 Party Place', " +
  29.                  "'Mendocino', 'CA', '95460')");
  30.         
  31.             stmt.executeUpdate("insert into SUPPLIERS " +
  32.                 "values(101, 'Acme, Inc.', '99 Market Street', " +
  33.                 "'Groundsville', 'CA', '95199')");
  34.     
  35.             stmt.executeUpdate("insert into SUPPLIERS " +
  36.                      "values(150, 'The High Ground', '100 Coffee Lane', " +
  37.                  "'Meadows', 'CA', '93966')");
  38.     
  39.             ResultSet rs = stmt.executeQuery(query);
  40.     
  41.             System.out.println("Suppliers and their ID Numbers:");
  42.             while (rs.next()) {
  43.                 String s = rs.getString("SUP_NAME");
  44.                 int n = rs.getInt("SUP_ID");
  45.                 System.out.println(s + "   " + n);
  46.             }
  47.     
  48.             stmt.close();
  49.             con.close();
  50.     
  51.         } catch(SQLException ex) {
  52.             System.err.println("SQLException: " + ex.getMessage());
  53.         }
  54.     }
  55. }
  56.  
  57.