Here you can find the source of fillPreparedStatementParams(PreparedStatement ps, Object... obj)
Parameter | Description |
---|---|
ps | UnpreparedStatement |
obj | Object |
Parameter | Description |
---|---|
SQLException | an exception |
private static void fillPreparedStatementParams(PreparedStatement ps, Object... obj) throws SQLException
//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); } } } }