Here you can find the source of queryAll(String sql, List
public static List<List<Object>> queryAll(String sql, List<Object> params)
//package com.java2s; //License from project: Open Source License import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; public class Main { private static final String url = "jdbc:mysql://192.168.1.100:3306/mx"; private static final String user = "root"; private static final String password = "admin"; public static List<List<Object>> queryAll(String sql, List<Object> params) { List<List<Object>> result = new ArrayList<List<Object>>(); Connection connection = null; try {/*w w w .j a va 2 s . co m*/ connection = DriverManager.getConnection(url, user, password); PreparedStatement ps = connection.prepareStatement(sql); if (params != null && params.size() > 0) { for (int i = 0; i < params.size(); i++) { ps.setObject(i + 1, params.get(i)); } } ResultSet resultset = ps.executeQuery(); int columnCount = resultset.getMetaData().getColumnCount(); while (resultset.next()) { List<Object> line = new ArrayList<Object>(); for (int i = 0; i < columnCount; i++) { Object value = resultset.getObject(i + 1); line.add(i, value); } result.add(line); } } catch (SQLException e) { e.printStackTrace(); } finally { if (connection != null) { try { connection.close(); } catch (SQLException e) { e.printStackTrace(); } } } return result; } }