Java SQL PreparedStatement setValue(PreparedStatement ps, int posicion, int tipo, String strDefault, String strValor)

Here you can find the source of setValue(PreparedStatement ps, int posicion, int tipo, String strDefault, String strValor)

Description

set Value

License

Apache License

Declaration

public static boolean setValue(PreparedStatement ps, int posicion, int tipo, String strDefault,
            String strValor) 

Method Source Code

//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);
    }
}

Related

  1. runInsertLong(PreparedStatement s)
  2. saveResourceInfoRecord(long resourceId, long propertyId, String propertyValue, String userId, PreparedStatement ps)
  3. setByte(PreparedStatement statement, int index, Byte value)
  4. setBytes(PreparedStatement pstmt, int index, byte[] bytes)
  5. setValue(PreparedStatement ps, int paramIndex, Object inValue)
  6. setValueIndex(PreparedStatement stmt, int index, int valueIndex)
  7. setValues(PreparedStatement preparedStatement, Object... values)
  8. setValues(PreparedStatement statement, Object... values)
  9. setValues(PreparedStatement statement, Object... values)