Here you can find the source of prepareStatement(Connection connection, String sql, Object... values)
Parameter | Description |
---|---|
connection | The Connection to create the PreparedStatement from. |
sql | The SQL query to construct the PreparedStatement with. |
values | The parameter values to be set in the created PreparedStatement. |
Parameter | Description |
---|---|
SQLException | If something fails during creating thePreparedStatement. |
public static PreparedStatement prepareStatement(Connection connection, String sql, Object... values) throws SQLException
//package com.java2s; //License from project: Apache License import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; public class Main { /**//from w w w . ja v a2 s .c o m * Returns a PreparedStatement of the given connection, set with the given * SQL query and the given parameter values. * * @param connection The Connection to create the PreparedStatement from. * @param sql The SQL query to construct the PreparedStatement with. * @param values The parameter values to be set in the created * PreparedStatement. * @return * @throws SQLException If something fails during creating the * PreparedStatement. */ public static PreparedStatement prepareStatement(Connection connection, String sql, Object... values) throws SQLException { PreparedStatement statement = connection.prepareStatement(sql); setValues(statement, values); return statement; } /** * Set the given parameter values in the given PreparedStatement. * * @param statement * @param values The parameter values to be set in the created * PreparedStatement. * @throws SQLException If something fails during setting the * PreparedStatement values. */ public static void setValues(PreparedStatement statement, Object... values) throws SQLException { for (int i = 0; i < values.length; i++) { statement.setObject(i + 1, values[i]); } } }