Here you can find the source of executeQuery2(java.sql.Connection con, String select, Object... pk)
public static String[] executeQuery2(java.sql.Connection con, String select, Object... pk) throws Exception
//package com.java2s; //License from project: GNU General Public License import java.util.ArrayList; public class Main { public static String[] executeQuery2(java.sql.Connection con, String select, Object... pk) throws Exception { con.setAutoCommit(true);/*from w w w . ja v a2 s . co m*/ java.sql.PreparedStatement ps = null; java.sql.ResultSet rs = null; try { ps = con.prepareStatement(select); if (pk != null) { for (int x = 0; x < pk.length; x++) { ps.setObject(x + 1, pk[x]); } } rs = ps.executeQuery(); Object obj; ArrayList<String> list = new ArrayList<String>(); java.sql.ResultSetMetaData rsmd = rs.getMetaData(); int numColumns = rsmd.getColumnCount(); while (rs.next()) { StringBuffer str = new StringBuffer(); for (int i = 2; i <= numColumns; i++) { if (i > 2) { str.trimToSize(); str.append(' '); } obj = rs.getObject(i); if (obj != null) { str.append(obj); } } list.add(str.toString()); } if (list.size() == 0) { return null; } else { return list.toArray(new String[list.size()]); } } finally { if (rs != null) { rs.close(); } if (ps != null) { ps.close(); } } } /** * * @param con * @param select * @param pk * @return * @throws Exception */ public static String executeQuery(java.sql.Connection con, String select, Object pk) throws Exception { con.setAutoCommit(true); java.sql.PreparedStatement ps = null; java.sql.ResultSet rs = null; try { ps = con.prepareStatement(select); ps.setObject(1, pk); rs = ps.executeQuery(); Object obj; if (rs.next()) { StringBuffer str = new StringBuffer(); java.sql.ResultSetMetaData rsmd = rs.getMetaData(); int numColumns = rsmd.getColumnCount(); for (int i = 2; i <= numColumns; i++) { if (i > 1) { str.trimToSize(); str.append(' '); } obj = rs.getObject(i); if (obj != null) { str.append(obj); } } return str.toString(); } else { return null; } } finally { if (rs != null) { rs.close(); } if (ps != null) { ps.close(); } } } }