Here you can find the source of fillStatement(PreparedStatement stmt, Object[] params)
PreparedStatement
replacement parameters with the given objects.
Parameter | Description |
---|---|
params | Query replacement parameters; <code>null</code> is a valid value to pass in. |
public static void fillStatement(PreparedStatement stmt, Object[] params) throws SQLException
//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); } } } }