Example usage for java.sql Types DATE

List of usage examples for java.sql Types DATE

Introduction

In this page you can find the example usage for java.sql Types DATE.

Prototype

int DATE

To view the source code for java.sql Types DATE.

Click Source Link

Document

The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DATE.

Usage

From source file:org.akaza.openclinica.dao.managestudy.StudySubjectDAO.java

/**
 * @deprecated Creates a new studysubject
 *///from w  w w  .jav a 2s. co m
@Override
@Deprecated
public EntityBean create(EntityBean eb) {
    StudySubjectBean sb = (StudySubjectBean) eb;
    HashMap variables = new HashMap();
    HashMap nullVars = new HashMap();

    // INSERT INTO study_subject
    // (LABEL, SUBJECT_ID, STUDY_ID, STATUS_ID,
    // DATE_CREATED, OWNER_ID, ENROLLMENT_DATE,SECONDARY_LABEL)
    // VALUES (?,?,?,?,NOW(),?,?,?)

    int ind = 1;
    variables.put(new Integer(ind), sb.getLabel());
    ind++;
    variables.put(new Integer(ind), new Integer(sb.getSubjectId()));
    ind++;
    variables.put(new Integer(ind), new Integer(sb.getStudyId()));
    ind++;
    variables.put(new Integer(ind), new Integer(sb.getStatus().getId()));
    ind++;
    // Date_created is now()
    variables.put(new Integer(ind), new Integer(sb.getOwnerId()));
    ind++;
    // variables.put(new Integer(ind), new Integer(sb.getStudyGroupId()));
    // ind++;
    if (sb.getEnrollmentDate() == null) {
        nullVars.put(new Integer(ind), new Integer(Types.DATE));
        variables.put(new Integer(ind), null);
        ind++;
    } else {
        variables.put(new Integer(ind), sb.getEnrollmentDate());
        ind++;
    }
    variables.put(new Integer(ind), sb.getSecondaryLabel());
    ind++;

    this.execute(digester.getQuery("create"), variables, nullVars);

    if (isQuerySuccessful()) {
        sb.setId(getCurrentPK());
    }

    return sb;
}

From source file:org.moqui.impl.entity.EntityJavaUtil.java

public static void setPreparedStatementValue(PreparedStatement ps, int index, Object value, FieldInfo fi,
        boolean useBinaryTypeForBlob, EntityFacade efi) throws EntityException {
    try {//from w  w  w . ja  va2  s.  com
        // allow setting, and searching for, String values for all types; JDBC driver should handle this okay
        if (value instanceof CharSequence) {
            ps.setString(index, value.toString());
        } else {
            switch (fi.typeValue) {
            case 1:
                if (value != null) {
                    ps.setString(index, value.toString());
                } else {
                    ps.setNull(index, Types.VARCHAR);
                }
                break;
            case 2:
                if (value != null) {
                    Class valClass = value.getClass();
                    if (valClass == Timestamp.class) {
                        ps.setTimestamp(index, (Timestamp) value, efi.getCalendarForTzLc());
                    } else if (valClass == java.sql.Date.class) {
                        ps.setDate(index, (java.sql.Date) value, efi.getCalendarForTzLc());
                    } else if (valClass == java.util.Date.class) {
                        ps.setTimestamp(index, new Timestamp(((java.util.Date) value).getTime()),
                                efi.getCalendarForTzLc());
                    } else {
                        throw new IllegalArgumentException("Class " + valClass.getName()
                                + " not allowed for date-time (Timestamp) fields, for field " + fi.entityName
                                + "." + fi.name);
                    }
                } else {
                    ps.setNull(index, Types.TIMESTAMP);
                }
                break;
            case 3:
                Time tm = (Time) value;
                // logger.warn("=================== setting time tm=${tm} tm long=${tm.getTime()}, cal=${cal}")
                if (value != null) {
                    ps.setTime(index, tm, efi.getCalendarForTzLc());
                } else {
                    ps.setNull(index, Types.TIME);
                }
                break;
            case 4:
                if (value != null) {
                    Class valClass = value.getClass();
                    if (valClass == java.sql.Date.class) {
                        java.sql.Date dt = (java.sql.Date) value;
                        // logger.warn("=================== setting date dt=${dt} dt long=${dt.getTime()}, cal=${cal}")
                        ps.setDate(index, dt, efi.getCalendarForTzLc());
                    } else if (valClass == Timestamp.class) {
                        ps.setDate(index, new java.sql.Date(((Timestamp) value).getTime()),
                                efi.getCalendarForTzLc());
                    } else if (valClass == java.util.Date.class) {
                        ps.setDate(index, new java.sql.Date(((java.util.Date) value).getTime()),
                                efi.getCalendarForTzLc());
                    } else {
                        throw new IllegalArgumentException("Class " + valClass.getName()
                                + " not allowed for date fields, for field " + fi.entityName + "." + fi.name);
                    }
                } else {
                    ps.setNull(index, Types.DATE);
                }
                break;
            case 5:
                if (value != null) {
                    ps.setInt(index, ((Number) value).intValue());
                } else {
                    ps.setNull(index, Types.NUMERIC);
                }
                break;
            case 6:
                if (value != null) {
                    ps.setLong(index, ((Number) value).longValue());
                } else {
                    ps.setNull(index, Types.NUMERIC);
                }
                break;
            case 7:
                if (value != null) {
                    ps.setFloat(index, ((Number) value).floatValue());
                } else {
                    ps.setNull(index, Types.NUMERIC);
                }
                break;
            case 8:
                if (value != null) {
                    ps.setDouble(index, ((Number) value).doubleValue());
                } else {
                    ps.setNull(index, Types.NUMERIC);
                }
                break;
            case 9:
                if (value != null) {
                    Class valClass = value.getClass();
                    // most common cases BigDecimal, Double, Float; then allow any Number
                    if (valClass == BigDecimal.class) {
                        ps.setBigDecimal(index, (BigDecimal) value);
                    } else if (valClass == Double.class) {
                        ps.setDouble(index, (Double) value);
                    } else if (valClass == Float.class) {
                        ps.setFloat(index, (Float) value);
                    } else if (value instanceof Number) {
                        ps.setDouble(index, ((Number) value).doubleValue());
                    } else {
                        throw new IllegalArgumentException("Class " + valClass.getName()
                                + " not allowed for number-decimal (BigDecimal) fields, for field "
                                + fi.entityName + "." + fi.name);
                    }
                } else {
                    ps.setNull(index, Types.NUMERIC);
                }
                break;
            case 10:
                if (value != null) {
                    ps.setBoolean(index, (Boolean) value);
                } else {
                    ps.setNull(index, Types.BOOLEAN);
                }
                break;
            case 11:
                if (value != null) {
                    try {
                        ByteArrayOutputStream os = new ByteArrayOutputStream();
                        ObjectOutputStream oos = new ObjectOutputStream(os);
                        oos.writeObject(value);
                        oos.close();
                        byte[] buf = os.toByteArray();
                        os.close();

                        ByteArrayInputStream is = new ByteArrayInputStream(buf);
                        ps.setBinaryStream(index, is, buf.length);
                        is.close();
                    } catch (IOException ex) {
                        throw new EntityException(
                                "Error setting serialized object, for field " + fi.entityName + "." + fi.name,
                                ex);
                    }
                } else {
                    if (useBinaryTypeForBlob) {
                        ps.setNull(index, Types.BINARY);
                    } else {
                        ps.setNull(index, Types.BLOB);
                    }
                }
                break;
            case 12:
                if (value instanceof byte[]) {
                    ps.setBytes(index, (byte[]) value);
                    /*
                    } else if (value instanceof ArrayList) {
                        ArrayList valueAl = (ArrayList) value;
                        byte[] theBytes = new byte[valueAl.size()];
                        valueAl.toArray(theBytes);
                        ps.setBytes(index, theBytes);
                    */
                } else if (value instanceof ByteBuffer) {
                    ByteBuffer valueBb = (ByteBuffer) value;
                    ps.setBytes(index, valueBb.array());
                } else if (value instanceof Blob) {
                    Blob valueBlob = (Blob) value;
                    // calling setBytes instead of setBlob
                    // ps.setBlob(index, (Blob) value)
                    // Blob blb = value
                    ps.setBytes(index, valueBlob.getBytes(1, (int) valueBlob.length()));
                } else {
                    if (value != null) {
                        throw new IllegalArgumentException("Type not supported for BLOB field: "
                                + value.getClass().getName() + ", for field " + fi.entityName + "." + fi.name);
                    } else {
                        if (useBinaryTypeForBlob) {
                            ps.setNull(index, Types.BINARY);
                        } else {
                            ps.setNull(index, Types.BLOB);
                        }
                    }
                }
                break;
            case 13:
                if (value != null) {
                    ps.setClob(index, (Clob) value);
                } else {
                    ps.setNull(index, Types.CLOB);
                }
                break;
            case 14:
                if (value != null) {
                    ps.setTimestamp(index, (Timestamp) value);
                } else {
                    ps.setNull(index, Types.TIMESTAMP);
                }
                break;
            // TODO: is this the best way to do collections and such?
            case 15:
                if (value != null) {
                    ps.setObject(index, value, Types.JAVA_OBJECT);
                } else {
                    ps.setNull(index, Types.JAVA_OBJECT);
                }
                break;
            }
        }
    } catch (SQLException sqle) {
        throw new EntityException("SQL Exception while setting value [" + value + "]("
                + (value != null ? value.getClass().getName() : "null") + "), type " + fi.type + ", for field "
                + fi.entityName + "." + fi.name + ": " + sqle.toString(), sqle);
    } catch (Exception e) {
        throw new EntityException(
                "Error while setting value for field " + fi.entityName + "." + fi.name + ": " + e.toString(),
                e);
    }
}

From source file:org.nuxeo.ecm.core.storage.sql.db.H2Fulltext.java

protected static String asString(Object data, int type) throws SQLException {
    if (data == null) {
        return "";
    }//from   ww  w.  j a  v a2 s.  co m
    switch (type) {
    case Types.BIT:
    case Types.BOOLEAN:
    case Types.INTEGER:
    case Types.BIGINT:
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.NUMERIC:
    case Types.REAL:
    case Types.SMALLINT:
    case Types.TINYINT:
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
    case Types.LONGVARCHAR:
    case Types.CHAR:
    case Types.VARCHAR:
        return data.toString();
    case Types.CLOB:
        try {
            if (data instanceof Clob) {
                data = ((Clob) data).getCharacterStream();
            }
            return IOUtils.readStringAndClose((Reader) data, -1);
        } catch (IOException e) {
            throw DbException.convert(e);
        }
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
    case Types.BINARY:
    case Types.JAVA_OBJECT:
    case Types.OTHER:
    case Types.BLOB:
    case Types.STRUCT:
    case Types.REF:
    case Types.NULL:
    case Types.ARRAY:
    case Types.DATALINK:
    case Types.DISTINCT:
        throw new SQLException("Unsupported column data type: " + type);
    default:
        return "";
    }
}

From source file:org.h2gis.drivers.osm.OSMParser.java

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    if (localName.compareToIgnoreCase("node") == 0) {
        tagLocation = TAG_LOCATION.OTHER;
        try {// www . j  a  va  2s. co m
            nodePreparedStmt.setObject(1, nodeOSMElement.getID());
            nodePreparedStmt.setObject(2, nodeOSMElement.getPoint(gf));
            nodePreparedStmt.setObject(3, nodeOSMElement.getElevation());
            nodePreparedStmt.setObject(4, nodeOSMElement.getUser());
            nodePreparedStmt.setObject(5, nodeOSMElement.getUID());
            nodePreparedStmt.setObject(6, nodeOSMElement.getVisible());
            nodePreparedStmt.setObject(7, nodeOSMElement.getVersion());
            nodePreparedStmt.setObject(8, nodeOSMElement.getChangeSet());
            nodePreparedStmt.setObject(9, nodeOSMElement.getTimeStamp(), Types.DATE);
            nodePreparedStmt.setString(10, nodeOSMElement.getName());
            nodePreparedStmt.addBatch();
            nodePreparedStmtBatchSize++;
            HashMap<String, String> tags = nodeOSMElement.getTags();
            for (Map.Entry<String, String> entry : tags.entrySet()) {
                nodeTagPreparedStmt.setObject(1, nodeOSMElement.getID());
                nodeTagPreparedStmt.setObject(2, entry.getKey());
                nodeTagPreparedStmt.setObject(3, entry.getValue());
                nodeTagPreparedStmt.addBatch();
                nodeTagPreparedStmtBatchSize++;
            }
        } catch (SQLException ex) {
            throw new SAXException("Cannot insert the node  :  " + nodeOSMElement.getID(), ex);
        }
    } else if (localName.compareToIgnoreCase("way") == 0) {
        tagLocation = TAG_LOCATION.OTHER;
        try {
            wayPreparedStmt.setObject(1, wayOSMElement.getID());
            wayPreparedStmt.setObject(2, wayOSMElement.getUser());
            wayPreparedStmt.setObject(3, wayOSMElement.getUID());
            wayPreparedStmt.setObject(4, wayOSMElement.getVisible());
            wayPreparedStmt.setObject(5, wayOSMElement.getVersion());
            wayPreparedStmt.setObject(6, wayOSMElement.getChangeSet());
            wayPreparedStmt.setTimestamp(7, wayOSMElement.getTimeStamp());
            wayPreparedStmt.setString(8, wayOSMElement.getName());
            wayPreparedStmt.addBatch();
            wayPreparedStmtBatchSize++;
            HashMap<String, String> tags = wayOSMElement.getTags();
            for (Map.Entry<String, String> entry : tags.entrySet()) {
                wayTagPreparedStmt.setObject(1, wayOSMElement.getID());
                wayTagPreparedStmt.setObject(2, entry.getKey());
                wayTagPreparedStmt.setObject(3, entry.getValue());
                wayTagPreparedStmt.addBatch();
                wayTagPreparedStmtBatchSize++;
            }
            int order = 1;
            for (long ref : wayOSMElement.getNodesRef()) {
                wayNodePreparedStmt.setObject(1, wayOSMElement.getID());
                wayNodePreparedStmt.setObject(2, ref);
                wayNodePreparedStmt.setObject(3, order++);
                wayNodePreparedStmt.addBatch();
                wayNodePreparedStmtBatchSize++;
            }
        } catch (SQLException ex) {
            throw new SAXException("Cannot insert the way  :  " + wayOSMElement.getID(), ex);
        }
    } else if (localName.compareToIgnoreCase("relation") == 0) {
        tagLocation = TAG_LOCATION.OTHER;
        try {
            relationPreparedStmt.setObject(1, relationOSMElement.getID());
            relationPreparedStmt.setObject(2, relationOSMElement.getUser());
            relationPreparedStmt.setObject(3, relationOSMElement.getUID());
            relationPreparedStmt.setObject(4, relationOSMElement.getVisible());
            relationPreparedStmt.setObject(5, relationOSMElement.getVersion());
            relationPreparedStmt.setObject(6, relationOSMElement.getChangeSet());
            relationPreparedStmt.setTimestamp(7, relationOSMElement.getTimeStamp());
            relationPreparedStmt.addBatch();
            relationPreparedStmtBatchSize++;
            HashMap<String, String> tags = relationOSMElement.getTags();
            for (Map.Entry<String, String> entry : tags.entrySet()) {
                relationTagPreparedStmt.setObject(1, relationOSMElement.getID());
                relationTagPreparedStmt.setObject(2, entry.getKey());
                relationTagPreparedStmt.setObject(3, entry.getValue());
                relationTagPreparedStmt.addBatch();
                relationTagPreparedStmtBatchSize++;
            }
            idMemberOrder = 0;
        } catch (SQLException ex) {
            throw new SAXException("Cannot insert the relation  :  " + relationOSMElement.getID(), ex);
        }
    } else if (localName.compareToIgnoreCase("member") == 0) {
        idMemberOrder++;
    }
    try {
        insertBatch();
    } catch (SQLException ex) {
        throw new SAXException("Could not insert sql batch", ex);
    }
    if (nodeCountProgress++ % readFileSizeEachNode == 0) {
        // Update Progress
        try {
            progress.setStep((int) (((double) fc.position() / fileSize) * 100));
        } catch (IOException ex) {
            // Ignore
        }
    }
}

From source file:org.exist.xquery.modules.oracle.ExecuteFunction.java

private void setParametersOnPreparedStatement(Statement stmt, Element parametersElement)
        throws SQLException, XPathException {

    if (parametersElement.getNamespaceURI().equals(OracleModule.NAMESPACE_URI)
            && parametersElement.getLocalName().equals(PARAMETERS_ELEMENT_NAME)) {
        NodeList paramElements = parametersElement.getElementsByTagNameNS(OracleModule.NAMESPACE_URI,
                PARAM_ELEMENT_NAME);/*from ww  w.j a v  a2 s  .  c  o  m*/

        for (int i = 0; i < paramElements.getLength(); i++) {
            Element param = ((Element) paramElements.item(i));
            String value = param.getFirstChild().getNodeValue();
            String type = param.getAttributeNS(OracleModule.NAMESPACE_URI, TYPE_ATTRIBUTE_NAME);
            int position = Integer
                    .parseInt(param.getAttributeNS(OracleModule.NAMESPACE_URI, POSITION_ATTRIBUTE_NAME));
            try {
                int sqlType = SQLUtils.sqlTypeFromString(type);
                // What if SQL type is date???
                if (sqlType == Types.DATE) {
                    Date date = xmlDf.parse(value);
                    ((PreparedStatement) stmt).setTimestamp(position, new Timestamp(date.getTime()));
                } else {
                    ((PreparedStatement) stmt).setObject(position, value, sqlType);
                }
            } catch (ParseException pex) {
                throw new XPathException(this, "Unable to parse date from value " + value
                        + ". Expected format is YYYY-MM-DDThh:mm:ss.sss");
            } catch (Exception ex) {
                throw new XPathException(this, "Failed to set stored procedure parameter at position "
                        + position + " as " + type + " with value " + value);
            }
        }
    }
}

From source file:com.streamsets.pipeline.lib.jdbc.multithread.TableContextUtil.java

public static String generateNextPartitionOffset(TableContext tableContext, String column, String offset) {
    final String partitionSize = tableContext.getOffsetColumnToPartitionOffsetAdjustments().get(column);
    switch (tableContext.getOffsetColumnToType().get(column)) {
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.INTEGER:
        final int int1 = Integer.parseInt(offset);
        final int int2 = Integer.parseInt(partitionSize);
        return String.valueOf(int1 + int2);
    case Types.TIMESTAMP:
        final Timestamp timestamp1 = getTimestampForOffsetValue(offset);
        final long timestampAdj = Long.parseLong(partitionSize);
        final Timestamp timestamp2 = Timestamp.from(timestamp1.toInstant().plusMillis(timestampAdj));
        return getOffsetValueForTimestamp(timestamp2);
    case Types.BIGINT:
        // TIME, DATE are represented as long (epoch)
    case Types.TIME:
    case Types.DATE:
        final long long1 = Long.parseLong(offset);
        final long long2 = Long.parseLong(partitionSize);
        return String.valueOf(long1 + long2);
    case Types.FLOAT:
    case Types.REAL:
        final float float1 = Float.parseFloat(offset);
        final float float2 = Float.parseFloat(partitionSize);
        return String.valueOf(float1 + float2);
    case Types.DOUBLE:
        final double double1 = Double.parseDouble(offset);
        final double double2 = Double.parseDouble(partitionSize);
        return String.valueOf(double1 + double2);
    case Types.NUMERIC:
    case Types.DECIMAL:
        final BigDecimal decimal1 = new BigDecimal(offset);
        final BigDecimal decimal2 = new BigDecimal(partitionSize);
        return decimal1.add(decimal2).toString();
    }// ww w.  j a  va  2s .  c  o  m
    return null;
}

From source file:org.jumpmind.db.platform.AbstractDatabasePlatform.java

public String[] getStringValues(BinaryEncoding encoding, Column[] metaData, Row row, boolean useVariableDates,
        boolean indexByPosition) {
    String[] values = new String[metaData.length];
    Set<String> keys = row.keySet();
    int i = 0;/*from w  w  w  .ja  va 2s.  c  o  m*/
    for (String key : keys) {
        Column column = metaData[i];
        String name = indexByPosition ? key : column.getName();
        int type = column.getJdbcTypeCode();
        if (row.get(name) != null) {
            if (type == Types.BOOLEAN || type == Types.BIT) {
                values[i] = row.getBoolean(name) ? "1" : "0";
            } else if (column.isOfNumericType()) {
                values[i] = row.getString(name);
            } else if (!column.isTimestampWithTimezone()
                    && (type == Types.DATE || type == Types.TIMESTAMP || type == Types.TIME)) {
                values[i] = getDateTimeStringValue(name, type, row, useVariableDates);
            } else if (column.isOfBinaryType()) {
                byte[] bytes = row.getBytes(name);
                if (encoding == BinaryEncoding.NONE) {
                    values[i] = row.getString(name);
                } else if (encoding == BinaryEncoding.BASE64) {
                    values[i] = new String(Base64.encodeBase64(bytes));
                } else if (encoding == BinaryEncoding.HEX) {
                    values[i] = new String(Hex.encodeHex(bytes));
                }
            } else {
                values[i] = row.getString(name);
            }
        }

        i++;
    }
    return values;
}

From source file:org.akaza.openclinica.dao.managestudy.StudyDAO.java

public StudyBean createStepTwo(StudyBean sb) {
    // UPDATE STUDY SET TYPE_ID=?, PROTOCOL_TYPE=?,PROTOCOL_DESCRIPTION=?,
    // PROTOCOL_DATE_VERIFICATION=?, PHASE=?, EXPECTED_TOTAL_ENROLLMENT=?,
    // SPONSOR=?, COLLABORATORS=?, MEDLINE_IDENTIFIER=?, URL=?,
    // URL_DESCRIPTION=?, CONDITIONS=?, KEYWORDS=?, ELIGIBILITY=?,
    // GENDER=?, AGE_MAX=?, AGE_MIN=?, HEALTHY_VOLUNTEER_ACCEPTED=?
    // WHERE STUDY_ID=?
    HashMap variables = new HashMap();
    HashMap nullVars = new HashMap();
    variables.put(new Integer(1), new Integer(sb.getType().getId()));
    variables.put(new Integer(2), sb.getProtocolTypeKey());
    variables.put(new Integer(3), sb.getProtocolDescription());

    if (sb.getProtocolDateVerification() == null) {
        nullVars.put(new Integer(4), new Integer(Types.DATE));
        variables.put(new Integer(4), null);
    } else {/*  w  w  w.j  a  va  2  s  . co m*/
        variables.put(new Integer(4), sb.getProtocolDateVerification());
    }

    variables.put(new Integer(5), sb.getPhaseKey());
    variables.put(new Integer(6), new Integer(sb.getExpectedTotalEnrollment()));
    variables.put(new Integer(7), sb.getSponsor());
    variables.put(new Integer(8), sb.getCollaborators());
    variables.put(new Integer(9), sb.getMedlineIdentifier());
    variables.put(new Integer(10), new Boolean(sb.isResultsReference()));
    variables.put(new Integer(11), sb.getUrl());
    variables.put(new Integer(12), sb.getUrlDescription());
    variables.put(new Integer(13), sb.getConditions());
    variables.put(new Integer(14), sb.getKeywords());
    variables.put(new Integer(15), sb.getEligibility());
    variables.put(new Integer(16), sb.getGenderKey());

    variables.put(new Integer(17), sb.getAgeMax());
    variables.put(new Integer(18), sb.getAgeMin());
    variables.put(new Integer(19), new Boolean(sb.getHealthyVolunteerAccepted()));
    variables.put(new Integer(20), sb.getSchemaName());
    if (sb.getStudyEnvUuid() == null) {
        nullVars.put(new Integer(21), new Integer(TypeNames.STRING));
        variables.put(new Integer(21), null);
    } else {
        variables.put(new Integer(21), sb.getStudyEnvUuid());
    }
    variables.put(new Integer(22), sb.getStudyEnvSiteUuid());
    variables.put(new Integer(23), sb.isPublished());
    variables.put(new Integer(24), sb.getFilePath());
    variables.put(new Integer(25), new Integer(sb.getId()));
    this.execute(digester.getQuery("createStepTwo"), variables, nullVars);
    return sb;
}

From source file:org.waarp.common.database.data.AbstractDbData.java

/**
 * Create the equivalent object in Json (no database access)
 * /* ww  w .  j av  a  2s.  com*/
 * @return The ObjectNode Json equivalent
 */
public ObjectNode getJson() {
    ObjectNode node = JsonHandler.createObjectNode();
    node.put(JSON_MODEL, this.getClass().getSimpleName());
    for (DbValue value : allFields) {
        if (value.column.equalsIgnoreCase("UPDATEDINFO")) {
            continue;
        }
        switch (value.type) {
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            node.put(value.column, (String) value.value);
            break;
        case Types.BIT:
            node.put(value.column, (Boolean) value.value);
            break;
        case Types.TINYINT:
            node.put(value.column, (Byte) value.value);
            break;
        case Types.SMALLINT:
            node.put(value.column, (Short) value.value);
            break;
        case Types.INTEGER:
            node.put(value.column, (Integer) value.value);
            break;
        case Types.BIGINT:
            node.put(value.column, (Long) value.value);
            break;
        case Types.REAL:
            node.put(value.column, (Float) value.value);
            break;
        case Types.DOUBLE:
            node.put(value.column, (Double) value.value);
            break;
        case Types.VARBINARY:
            node.put(value.column, (byte[]) value.value);
            break;
        case Types.DATE:
            node.put(value.column, ((Date) value.value).getTime());
            break;
        case Types.TIMESTAMP:
            node.put(value.column, ((Timestamp) value.value).getTime());
            break;
        case Types.CLOB:
        case Types.BLOB:
        default:
            node.put(value.column, "Unsupported type=" + value.type);
        }
    }
    return node;
}

From source file:architecture.ee.web.community.page.dao.jdbc.JdbcPageDao.java

private void updatePageVersion(Page page, int prevVersionId) {
    Date now = Calendar.getInstance().getTime();

    if (page.getPageState() == PageState.PUBLISHED) {
        getExtendedJdbcTemplate().update(
                getBoundSql("ARCHITECTURE_COMMUNITY.UPDATE_PAGE_STATE_TO_ARCHIVED").getSql(),
                new SqlParameterValue(Types.NUMERIC, page.getPageId()),
                new SqlParameterValue(Types.NUMERIC, page.getVersionId()));
    }/*from   w ww  . j a  va  2  s.  com*/
    if (page.getVersionId() > 0) {
        page.setModifiedDate(now);
        long modifierId = page.getUser().getUserId() <= 0L ? page.getUser().getUserId()
                : page.getUser().getUserId();
        // update page version
        getExtendedJdbcTemplate().update(getBoundSql("ARCHITECTURE_COMMUNITY.UPDATE_PAGE_VERSION").getSql(),
                new SqlParameterValue(Types.VARCHAR, page.getPageState().name().toLowerCase()),
                new SqlParameterValue(Types.VARCHAR, page.getTitle()),
                new SqlParameterValue(Types.VARCHAR, page.getSummary()),
                new SqlParameterValue(Types.NUMERIC, modifierId),
                new SqlParameterValue(Types.DATE, page.getModifiedDate()),
                new SqlParameterValue(Types.NUMERIC, page.getPageId()),
                new SqlParameterValue(Types.NUMERIC, page.getVersionId()));

    }
}