Code example for PreparedStatement

Methods: setObject

0
     
    public void setParameter(PreparedStatement ps, int colIndex, Object value, String name) throws Exception{
        if( value instanceof java.util.Date ) {
            value = parseDate((java.util.Date) value);
        } 
        ps.setObject(colIndex,value);
    } 
     
    private static final Format TS_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
     
    private Object parseDate(java.util.Date value) {
        if( value instanceof java.sql.Date )      return value;
        if( value instanceof java.sql.Timestamp ) return value;
         
        String dtstr = TS_FORMAT.format(value);
        return java.sql.Timestamp.valueOf(dtstr);
    } 
     
}