import java.sql.*; public class Test { private static String DB_URL = "jdbc:mysql://localhost:3306/quickstart"; private static String DB_USER = "root"; private static String DB_PWD = "password"; public static void run (String col, boolean direct) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con = DriverManager.getConnection(DB_URL, DB_USER, DB_PWD); String statement = "select " + col + " from t1 where " + col + " like " + (direct ? "'%%'" : "?"); PreparedStatement prep = con.prepareStatement(statement); if (!direct) prep.setString(1, "%%"); ResultSet rs = prep.executeQuery(); int count = 0; while (rs.next()) { System.out.println(rs.getString(1)); count++; } prep.close(); con.close(); System.out.println("Find " + count + " items totally by " + col + (direct ? " " : " un") + "directly\n"); } catch (Exception e) { System.out.println(e); } } public static void main (String[] args) { run ("etext", false); run ("gtext", false); run ("utext", false); run ("utext", true); } }