Java SQL Type addParameter(PreparedStatement smt, int index, Object value)

Here you can find the source of addParameter(PreparedStatement smt, int index, Object value)

Description

Add a paramenter (object) in the index position to an prepared stament

License

Apache License

Parameter

Parameter Description
smt the statment with the params
index the index of params
value the param value

Exception

Parameter Description

Declaration

public static void addParameter(PreparedStatement smt, int index, Object value) throws SQLException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.math.BigDecimal;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;

public class Main {
    /**/*from  w ww  .j a  v  a2  s  .c om*/
     * Add a paramenter (object) in the index position to an prepared stament
     * @param smt the statment with the params
     * @param index the index of params
     * @param value the param value
     * @throws java.sql.SQLException
     */
    public static void addParameter(PreparedStatement smt, int index, Object value) throws SQLException {
        if (value instanceof String) {
            smt.setString(index, value + "");
        } else if (value instanceof Integer) {
            smt.setInt(index, (Integer) value);
        } else if (value instanceof Double) {
            smt.setDouble(index, (Double) value);
        } else if (value instanceof Float) {
            smt.setFloat(index, (Float) value);
        } else if (value instanceof BigDecimal) {
            smt.setBigDecimal(index, (BigDecimal) value);
        } else if (value instanceof Date) {
            smt.setDate(index, (java.sql.Date) value);
        } else if (value instanceof Long) {
            smt.setLong(index, (Long) value);
        } else if (value instanceof Short) {
            smt.setShort(index, (Short) value);
        } else if (value instanceof Blob) {
            smt.setBlob(index, (Blob) value);
        } else if (value instanceof byte[]) {
            smt.setBytes(index, (byte[]) value);
        } else if (value instanceof Byte) {
            smt.setByte(index, (Byte) value);
        } else if (value instanceof Clob) {
            smt.setClob(index, (Clob) value);
        } else {
            smt.setObject(index, value);
        }
    }
}

Related

  1. adjustLevel(String attribute, int type)
  2. callPro2(String sql, String[] inparameters, Integer[] outparameters)
  3. columnClassName(int columnType)
  4. columnDisplaySize(int columnType)