Java SQL PreparedStatement fillStatement(PreparedStatement stmt, Object[] params)

Here you can find the source of fillStatement(PreparedStatement stmt, Object[] params)

Description

Fill the PreparedStatement replacement parameters with the given objects.

License

Apache License

Parameter

Parameter Description
params Query replacement parameters; <code>null</code> is a valid value to pass in.

Declaration

public static void fillStatement(PreparedStatement stmt, Object[] params) throws SQLException 

Method Source Code

//package com.java2s;
/*/* w  w w .jav  a  2s .c om*/
 * @(#)$Id$
 *
 * Copyright 2003-2004 The Apache Software Foundation
 * Copyright 2006-2008 Makoto YUI
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * Contributors:
 *     Makoto YUI - ported from jakarta commons DBUtils
 */

import java.sql.PreparedStatement;

import java.sql.SQLException;

import java.sql.Types;

public class Main {
    /**
     * Fill the <code>PreparedStatement</code> replacement parameters with 
     * the given objects.
     * 
     * @param params Query replacement parameters; <code>null</code> is a valid value to pass in.
     */
    public static void fillStatement(PreparedStatement stmt, Object[] params) throws SQLException {
        if (params == null) {
            return;
        }
        for (int i = 0; i < params.length; i++) {
            if (params[i] != null) {
                stmt.setObject(i + 1, params[i]);
            } else {
                // VARCHAR works with many drivers regardless
                // of the actual column type.  Oddly, NULL and 
                // OTHER don't work with Oracle's drivers.
                stmt.setNull(i + 1, Types.VARCHAR);
            }
        }
    }
}

Related

  1. fillArgs(Object[][] args, PreparedStatement pstmt, int i)
  2. fillInClause(PreparedStatement ps, int startIndex, Collection clauses, int sqlType)
  3. fillParameters(PreparedStatement stmt, List params)
  4. fillPreparedStatementParams(PreparedStatement ps, Object... obj)
  5. fillStatement(PreparedStatement ps,Object...params)
  6. getFileContent(final File file)
  7. getGeneratedKey(PreparedStatement ps)
  8. getGenerateKey(PreparedStatement stmt)
  9. getIdentity(PreparedStatement stat)

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