Revision history [back]

click to hide/show revision 1
initial version

answered 2009-04-20 19:55:47 +0800

YamilBracho gravatar image YamilBracho

Change to

public void update(String editStatement) throws SQLException { //also for insert
  Connection conn = null;
  PreparedStatement stmt = null;

  try {
    //load driver and get a database connection
    //Note: It is usually better to use connection pool. Please consult
    //the manual of your Web server. Or, refer to the Developer's Guide
    Class.forName("com.mysql.jdbc.Driver");
    String url = "jdbc:mysql://"+DB_host+":"+DB_port+"/"+DB_database;
    con = DriverManager.getConnection(url,"user", "");

    stmt = con.prepareStatement(editStatement);

  //execute the statement

      int rs = stmt.executeUpdate();
  } catch (ClassNotFoundException cnfe) {
      System.out.println("Class not found exception");
  } catch (SQLException se) {
      System.out.println("We got an exception while executing our query:" +
      "that probably means our SQL is invalid");
        se.printStackTrace();
        System.exit(1);
  } catch (Exception ex) {
      ex.printStackTrace();
  } finally {
     if (stmt != null) { 
       try { 
         stmt.close() 
       } catch (Exception ex) {}
     }

     if (conn != null) {
       try {
         conn.close();
       } catch (Exception ex) {}
     }
  }
}
Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More