Code example for PreparedStatement

Methods: setObject

    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);
    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);
Connect your IDE to all the code out there  Get Codota for Java