Java SQL PreparedStatement fillPreparedStatementParams(PreparedStatement ps, Object... obj)

Here you can find the source of fillPreparedStatementParams(PreparedStatement ps, Object... obj)

Description

Function is the same as it's name.

License

Apache License

Parameter

Parameter Description
ps UnpreparedStatement
obj Object

Exception

Parameter Description
SQLException an exception

Declaration

private static void fillPreparedStatementParams(PreparedStatement ps, Object... obj) throws SQLException 

Method Source Code

//package com.java2s;
/*//  w w w .j  av a  2 s.c  o m
 * Copyright 2017 ZhangJiupeng
 *
 * 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.
 */

import java.sql.*;

public class Main {
    /**
     * Function is the same as it's name.
     *
     * @param ps  UnpreparedStatement
     * @param obj Object
     * @throws SQLException
     */
    private static void fillPreparedStatementParams(PreparedStatement ps, Object... obj) throws SQLException {
        for (int i = 0; i < obj.length; i++) {
            Object target = obj[i];
            if (target == null) {
                ps.setNull(i + 1, Types.JAVA_OBJECT);
            } else {
                ps.setObject(i + 1, target.getClass() == Character.class ? String.valueOf(target) : target);
            }
        }
    }
}

Related

  1. createProjectInfo(PreparedStatement ps, long projectId, long projectInfoTypeId, String value, long modUserId)
  2. deleteOldData(Connection connection, PreparedStatement stmt, String funcId)
  3. fillArgs(Object[][] args, PreparedStatement pstmt, int i)
  4. fillInClause(PreparedStatement ps, int startIndex, Collection clauses, int sqlType)
  5. fillParameters(PreparedStatement stmt, List params)
  6. fillStatement(PreparedStatement ps,Object...params)
  7. fillStatement(PreparedStatement stmt, Object[] params)
  8. getFileContent(final File file)
  9. getGeneratedKey(PreparedStatement ps)

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