Here you can find the source of doSelect(DataSource ds, String tableName, int id)
public static List<String> doSelect(DataSource ds, String tableName, int id)
//package com.java2s; import javax.sql.DataSource; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; public class Main { private static final String ID_COLUMN_NAME = "id"; private static final String VALUE_COLUMN_NAME = "a"; public static List<String> doSelect(DataSource ds, String tableName, int id) { try (Connection conn = ds.getConnection()) { ResultSet resultset = conn.createStatement().executeQuery(String .format("SELECT %s FROM %s WHERE %s = %s", VALUE_COLUMN_NAME, tableName, ID_COLUMN_NAME, id)); List<String> result = new ArrayList<>(); while (resultset.next()) { result.add(resultset.getString(1)); }// w w w. j a v a 2s . c om return result; } catch (SQLException sqle) { throw new RuntimeException("Select of id " + id + " in table " + tableName + " failed", sqle); } } }