Here you can find the source of setValue(PreparedStatement ps, int posicion, int tipo, String strDefault, String strValor)
public static boolean setValue(PreparedStatement ps, int posicion, int tipo, String strDefault, String strValor)
//package com.java2s; /*/*from w w w. j av a 2 s . co m*/ ************************************************************************************ * Copyright (C) 2001-2010 Openbravo S.L.U. * Licensed under the Apache Software License version 2.0 * 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.PreparedStatement; public class Main { public static boolean setValue(PreparedStatement ps, int posicion, int tipo, String strDefault, String strValor) { try { if (strValor == null) { strValor = strDefault; } if (strValor != null) { if (strValor.compareTo("") == 0) ps.setNull(posicion, tipo); else { switch (tipo) { case 2: ps.setLong(posicion, Long.valueOf(strValor).longValue()); break; case 12: ps.setString(posicion, strValor); break; case java.sql.Types.LONGVARCHAR: ps.setString(posicion, strValor); break; case 0: ps.setDouble(posicion, Double.valueOf(strValor).doubleValue()); break; } } } else ps.setNull(posicion, tipo); } catch (Exception e) { e.printStackTrace(); return (false); } return (true); } }