Here you can find the source of executeForResult(Connection conn, String query, String... args)
public static ResultSet executeForResult(Connection conn, String query, String... args) throws SQLException
//package com.java2s; /*/* w w w . j a v a 2 s . c o m*/ * Copyright (C) 2009 Josh Guilfoyle <jasta@devtcg.org> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. */ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class Main { public static ResultSet executeForResult(Connection conn, String query, String... args) throws SQLException { if (args == null || args.length == 0) return conn.createStatement().executeQuery(query); else { PreparedStatement stmt = createPreparedStatement(conn, query, args); return stmt.executeQuery(); } } private static PreparedStatement createPreparedStatement(Connection conn, String sql, String[] args) throws SQLException { PreparedStatement stmt = conn.prepareStatement(sql); int n = args.length; for (int i = 0; i < n; i++) stmt.setString(i + 1, args[i]); return stmt; } }