import java.sql.*; public class SQLHelper { private final static String JDBC_USER = "mysql"; private final static String JDBC_PASSWD = ""; private final static String JDBC_DRIVER = "org.gjt.mm.mysql.Driver"; private final static String JDBC_URL = "jdbc:mysql://localhost:3306/asset"; public SQLHelper() { try { Class.forName(JDBC_DRIVER); } catch(ClassNotFoundException cnfe) { System.out.println("Error loading JDBC Driver: " + cnfe.getMessage()); } } public String sampleSubmit(/* parameters */) { StringBuffer sb = new StringBuffer(); try { String sql = "insert into XXX (FIELD1, FIELD2, ..., FIELDN) values "; // sql += "('" + VALUE1 + "','" + VALUE2 + "')"; Connection connection = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWD); Statement statement = connection.createStatement(); int num = statement.executeUpdate(sql); statement.close(); connection.close(); sb.append("

Inserted " + num + " new Row(s)

"); } catch(SQLException sqle) { sb.append("

Error:

" + sqle); } finally { return sb.toString(); } } public String getData(/* parameters */) { StringBuffer sb = new StringBuffer(); try { Connection connection = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWD); Statement statement = connection.createStatement(); String sql = "select FIELD1, FIELD2, ..., FIELDN from XXX"; ResultSet results = statement.executeQuery(sql); sb.append("
"); while (results.next()) { int id = results.getInt(1); String title = results.getString(2); String description = results.getString(3); sb.append(""); } sb.append("
" + title + "
"); results.close(); statement.close(); connection.close(); } catch(SQLException sqle) { sb.append("

Error

" + sqle); } return sb.toString(); } private String getToday() { Date today = new Date(System.currentTimeMillis()); return "'" + today.toString() + "'"; } }