Here you can find the source of execute(Connection conn, String sql, Object[] params)
public static List<Object[]> execute(Connection conn, String sql, Object[] params)
//package com.java2s; //License from project: Open Source License import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.util.ArrayList; import java.util.List; public class Main { public static List<Object[]> execute(Connection conn, String sql, Object[] params) { List<Object[]> result = new ArrayList<Object[]>(); PreparedStatement ps = null; ResultSet rs = null;//from ww w . ja v a 2 s . co m try { ps = conn.prepareStatement(sql); for (int i = 0; i < params.length; i++) { Object obj = params[i]; ps.setObject(i + 1, obj); } rs = ps.executeQuery(); ResultSetMetaData metaData = rs.getMetaData(); while (rs.next()) { int columnNum = metaData.getColumnCount(); Object[] values = new Object[columnNum]; for (int i = 0; i < values.length; i++) { values[i] = rs.getObject(i + 1); } result.add(values); } } catch (Exception e) { e.printStackTrace(); } return result; } }