Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 7th, 2012  |  syntax: Java  |  size: 0.85 KB  |  hits: 30  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.         public static Connection connect() {
  2.  
  3.         Connection con;
  4.         try {
  5.  
  6.             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  7.             String filename = Global.global.path+"jordonian_project_db.mdb";
  8.             String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+filename.trim()+";DriverID=22;READONLY=true}";
  9.             con = DriverManager.getConnection(database, "", "");
  10.  
  11.         } catch (Exception ex) {
  12.                 ex.printStackTrace();
  13.             return null;
  14.         }
  15.         return con;
  16.     }
  17.        
  18.         public static void insertNjp() throws SQLException{
  19.                 Statement st = connect().createStatement();
  20.                 for(NjpEntry entry : Global.global.njpEntries){
  21.                         String sql = "INSERT INTO NjpEntry (name, desc) VALUES (\'"+entry.name+"\',\'"+entry.desc+"\')";
  22.                         System.out.println(sql);
  23.                         st.executeUpdate(sql);
  24.                 }
  25.         }