Java SQL PreparedStatement prepareStatement(Connection connection, String sql, boolean returnKeys, Object... values)

Here you can find the source of prepareStatement(Connection connection, String sql, boolean returnKeys, Object... values)

Description

prepare Statement

License

Apache License

Declaration

public static PreparedStatement prepareStatement(Connection connection, String sql, boolean returnKeys,
            Object... values) throws SQLException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    public static PreparedStatement prepareStatement(Connection connection, String sql, boolean returnKeys,
            Object... values) throws SQLException {
        PreparedStatement statement = connection.prepareStatement(sql,
                returnKeys ? Statement.RETURN_GENERATED_KEYS : Statement.NO_GENERATED_KEYS);
        setValues(statement, values);/*from  w w w  .ja va  2s. com*/
        return statement;
    }

    public static void setValues(PreparedStatement statement, Object[] values) throws SQLException {
        for (int i = 0; i < values.length; i++) {
            statement.setObject(i + 1, values[i]);
        }
    }
}

Related

  1. prepareStatement(Connection conn, String name, String sql)
  2. prepareStatement(Connection conn, String sql)
  3. prepareStatement(Connection conn, String sql, boolean isCallable)
  4. prepareStatement(Connection conn, String sql, Object... values)
  5. prepareStatement(Connection connection, String line)
  6. prepareStatement(Connection connection, String sql, Object... values)
  7. prepareStatement(String parameterizedSQL, List values, Connection conn)
  8. prepareStatement(String parameterizedSQL, List values, Connection conn)
  9. prepareStatement(String query)

  10. HOME | Copyright © www.java2s.com 2016