title: Insert data to ms access from java
body: <p>I'm new to JDBC. I want to insert data into Access from Java, but I can't get it. It shows the following error:</p>
  
  <pre><code>Connection Established Successfully  
  java.sql.SQLException: General error  
  Could Not Connect to Database  
      at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)  
      at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)  
      at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)  
      at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)  
      at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(Unknown Source)  
      at DBConnect.&lt;init&gt;(DBConnect.java:22)  
      at DBConnect.main(DBConnect.java:32)  
  </code></pre>
  
  <p>code:</p>
  
  <pre><code>public DBConnect() {
      File f = new File("DB.accdb");
      try{
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          System.out.println("DriverLoaded");
          String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + f.getAbsolutePath();
          Connection con = DriverManager.getConnection(url);
          System.out.println("Connection Established Successfully");
  
          Statement st=con.createStatement();
          String productId="1";
          String desc="Jambu";
          int quantity=10;
          double price = 2.0, disc=1.0;
          st.executeUpdate("INSERT into Product(productID,description,quantity,price,discount) VALUES('"+productId+"','"+desc+"','"+quantity+"','"+price+"','"+disc+"')");
          System.out.println("Row is added");
      }catch(Exception e) {
          e.printStackTrace();
          System.out.println("Could Not Connect to Database");
      }
  </code></pre>