Here you can find the source of query(List
Parameter | Description |
---|---|
mapper | query parameters |
conn | a parameter |
pstmt | a parameter |
Parameter | Description |
---|---|
SQLException | an exception |
public static ResultSet query(List<String> paramList, Connection conn, PreparedStatement pstmt) throws SQLException
//package com.java2s; //License from project: Apache License import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Iterator; import java.util.List; public class Main { /**// ww w . j av a 2 s.c o m * Don't forget: After execute query, we need to close resultset, prepared statement and connection in * persistence layer * @param mapper query parameters * @param conn * @param pstmt * @return * @throws SQLException */ public static ResultSet query(List<String> paramList, Connection conn, PreparedStatement pstmt) throws SQLException { ResultSet result = null; try { Iterator<String> paramIter = paramList.iterator(); int i = 1; while (paramIter.hasNext()) { String eachParam = paramIter.next(); pstmt.setString(i, eachParam); i++; } result = pstmt.executeQuery(); } catch (Exception ex) { ex.printStackTrace(); } return result; } /** * Don't forget: After execute query, we need to close resultset, prepared statement and connection in * persistence layer * @param mapper query parameters * @param conn * @param pstmt * @return * @throws SQLException */ public static ResultSet query(Connection conn, PreparedStatement pstmt) throws SQLException { ResultSet result = null; try { result = pstmt.executeQuery(); } catch (Exception ex) { ex.printStackTrace(); } return result; } }