Here you can find the source of executeQuery(java.sql.Connection con, String select, Object pk)
Parameter | Description |
---|---|
con | a parameter |
select | a parameter |
pk | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
public static String executeQuery(java.sql.Connection con, String select, Object pk) throws Exception
//package com.java2s; //License from project: GNU General Public License public class Main { /**/*from w ww .j a v a2s . c om*/ * * @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(); } } } }