Here you can find the source of createInQueryStatement(String query, long[] ids, Connection conn)
Parameter | Description |
---|---|
query | the query to be use. |
ids | the submission id. |
conn | the connection to be used. |
Parameter | Description |
---|---|
SQLException | if error occurs during operation. |
static PreparedStatement createInQueryStatement(String query, long[] ids, Connection conn) throws SQLException
//package com.java2s; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; public class Main { /**// ww w . j a v a 2s.com * Creates new PreparedStatement and fill it up with the ids. * * @param query the query to be use. * @param ids the submission id. * @param conn the connection to be used. * @return the prepared statement filled with id values. * @throws SQLException if error occurs during operation. */ static PreparedStatement createInQueryStatement(String query, long[] ids, Connection conn) throws SQLException { String actualQuery = query + createQuestionMarks(ids.length); PreparedStatement pstmt = conn.prepareStatement(actualQuery); for (int i = 0; i < ids.length; i++) { pstmt.setLong(i + 1, ids[i]); } return pstmt; } /** * Creates the string in the pattern (?,+) where count is the number of question marks. It is used th build * prepared statements with IN condition. * * @param count number of question marks. * @return the string of question marks. */ static String createQuestionMarks(int count) { StringBuffer buff = new StringBuffer(); buff.append("(?"); for (int i = 1; i < count; i++) { buff.append(", ?"); } buff.append(")"); return buff.toString(); } }