Here you can find the source of doInsert(DataSource ds, String tableName, int id, String value)
public static void doInsert(DataSource ds, String tableName, int id, String value)
//package com.java2s; import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; public class Main { public static void doInsert(DataSource ds, String tableName, int id, String value) { try (Connection conn = ds.getConnection()) { int updated = conn.createStatement() .executeUpdate(String.format("INSERT INTO %s (id, a) VALUES (%s,'%s')", tableName, id, value)); System.out.println("INSERT to table " + tableName + " outcome: " + updated); } catch (SQLException sqle) { throw new RuntimeException("insert failed", sqle); }//from w ww .j av a 2s. co m } }