List of usage examples for java.sql Types DATE
int DATE
To view the source code for java.sql Types DATE.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DATE
.
From source file:lasige.steeldb.jdbc.BFTRowSet.java
/** * Indicates whether the given SQL data type is a temporal type. * This method is called internally by the conversion methods * <code>convertNumeric</code> and <code>convertTemporal</code>. * * @param type one of the constants from <code>java.sql.Types</code> * @return <code>true</code> if the given type is <code>DATE</code>, * <code>TIME</code>, or <code>TIMESTAMP</code>; * <code>false</code> otherwise *//*from w w w . j a va2 s.com*/ private boolean isTemporal(int type) { switch (type) { case java.sql.Types.DATE: case java.sql.Types.TIME: case java.sql.Types.TIMESTAMP: return true; default: return false; } }
From source file:lasige.steeldb.jdbc.BFTRowSet.java
/** * Converts the given <code>Object</code> in the Java programming language * to the standard object mapping for the specified SQL target data type. * The conversion must be to a string or temporal type, and there are also * restrictions on the type to be converted. * <P>//from www. jav a2 s . com * <TABLE ALIGN="CENTER" BORDER CELLPADDING=10 BORDERCOLOR="#0000FF" * <CAPTION ALIGN="CENTER"><B>Parameters and Return Values</B></CAPTION> * <TR> * <TD><B>Source SQL Type</B> * <TD><B>Target SQL Type</B> * <TD><B>Object Returned</B> * </TR> * <TR> * <TD><code>TIMESTAMP</code> * <TD><code>DATE</code> * <TD><code>java.sql.Date</code> * </TR> * <TR> * <TD><code>TIMESTAMP</code> * <TD><code>TIME</code> * <TD><code>java.sql.Time</code> * </TR> * <TR> * <TD><code>TIME</code> * <TD><code>TIMESTAMP</code> * <TD><code>java.sql.Timestamp</code> * </TR> * <TR> * <TD><code>DATE</code>, <code>TIME</code>, or <code>TIMESTAMP</code> * <TD><code>CHAR</code>, <code>VARCHAR</code>, or <code>LONGVARCHAR</code> * <TD><code>java.lang.String</code> * </TR> * </TABLE> * <P> * If the source type and target type are the same, * the given object is simply returned. * * @param srcObj the <code>Object</code> in the Java programming language * that is to be converted to the target type * @param srcType the data type that is the standard mapping in SQL of the * object to be converted; must be one of the constants in * <code>java.sql.Types</code> * @param trgType the SQL data type to which to convert the given object; * must be one of the following constants in * <code>java.sql.Types</code>: <code>DATE</code>, * <code>TIME</code>, <code>TIMESTAMP</code>, <code>CHAR</code>, * <code>VARCHAR</code>, or <code>LONGVARCHAR</code> * @return an <code>Object</code> value.that is * the standard object mapping for the target SQL type * @throws SQLException if the given target type is not one of the string or * temporal types in <code>java.sql.Types</code> */ private Object convertTemporal(Object srcObj, int srcType, int trgType) throws SQLException { if (srcType == trgType) { return srcObj; } if (isNumeric(trgType) == true || (isString(trgType) == false && isTemporal(trgType) == false)) { throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString()); } try { switch (trgType) { case java.sql.Types.DATE: if (srcType == java.sql.Types.TIMESTAMP) { return new java.sql.Date(((java.sql.Timestamp) srcObj).getTime()); } else { throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString()); } case java.sql.Types.TIMESTAMP: if (srcType == java.sql.Types.TIME) { return new Timestamp(((java.sql.Time) srcObj).getTime()); } else { return new Timestamp(((java.sql.Date) srcObj).getTime()); } case java.sql.Types.TIME: if (srcType == java.sql.Types.TIMESTAMP) { return new Time(((java.sql.Timestamp) srcObj).getTime()); } else { throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString()); } case java.sql.Types.CHAR: case java.sql.Types.VARCHAR: case java.sql.Types.LONGVARCHAR: return new String(srcObj.toString()); default: throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString()); } } catch (NumberFormatException ex) { throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString()); } }
From source file:lasige.steeldb.jdbc.BFTRowSet.java
/** * Sets the designated column in either the current row or the insert * row of this <code>CachedRowSetImpl</code> object with the given * <code>Date</code> object. * * This method updates a column value in either the current row or * the insert row of this rowset, but it does not update the * database. If the cursor is on a row in the rowset, the * method {@link #updateRow} must be called to update the database. * If the cursor is on the insert row, the method {@link #insertRow} * must be called, which will insert the new row into both this rowset * and the database. Both of these methods must be called before the * cursor moves to another row./*from ww w . ja v a 2 s. c o m*/ * * @param columnIndex the first column is <code>1</code>, the second * is <code>2</code>, and so on; must be <code>1</code> or larger * and equal to or less than the number of columns in this rowset * @param x the new column value * @throws SQLException if (1) the given column index is out of bounds, * (2) the cursor is not on one of this rowset's rows or its * insert row, (3) the type of the designated column is not * an SQL <code>DATE</code> or <code>TIMESTAMP</code>, or * (4) this rowset is <code>ResultSet.CONCUR_READ_ONLY</code> */ public void updateDate(int columnIndex, java.sql.Date x) throws SQLException { // sanity check. checkIndex(columnIndex); // make sure the cursor is on a valid row checkCursor(); Object obj = convertTemporal(x, java.sql.Types.DATE, RowSetMD.getColumnType(columnIndex)); getCurrentRow().setColumnObject(columnIndex, obj); }
From source file:lasige.steeldb.jdbc.BFTRowSet.java
/** * Retrieves the value of the designated column in the current row * of this <code>CachedRowSetImpl</code> object as a <code>java.sql.Date</code> * object, using the given <code>Calendar</code> object to construct an * appropriate millisecond value for the date. * * @param columnIndex the first column is <code>1</code>, the second * is <code>2</code>, and so on; must be <code>1</code> or larger * and equal to or less than the number of columns in the rowset * @param cal the <code>java.util.Calendar</code> object to use in * constructing the date/* ww w . j av a2 s . c om*/ * @return the column value; if the value is SQL <code>NULL</code>, * the result is <code>null</code> * @throws SQLException if (1) the given column name is not the name of * a column in this rowset, (2) the cursor is not on one of * this rowset's rows or its insert row, or (3) the designated * column does not store an SQL <code>DATE</code> or * <code>TIMESTAMP</code> value */ public java.sql.Date getDate(int columnIndex, Calendar cal) throws SQLException { Object value; // sanity check. checkIndex(columnIndex); // make sure the cursor is on a valid row checkCursor(); setLastValueNull(false); value = getCurrentRow().getColumnObject(columnIndex); // check for SQL NULL if (value == null) { setLastValueNull(true); return null; } value = convertTemporal(value, RowSetMD.getColumnType(columnIndex), java.sql.Types.DATE); // create a default calendar Calendar defaultCal = Calendar.getInstance(); // set this Calendar to the time we have defaultCal.setTime((java.util.Date) value); /* * Now we can pull the pieces of the date out * of the default calendar and put them into * the user provided calendar */ cal.set(Calendar.YEAR, defaultCal.get(Calendar.YEAR)); cal.set(Calendar.MONTH, defaultCal.get(Calendar.MONTH)); cal.set(Calendar.DAY_OF_MONTH, defaultCal.get(Calendar.DAY_OF_MONTH)); /* * This looks a little odd but it is correct - * Calendar.getTime() returns a Date... */ return new java.sql.Date(cal.getTime().getTime()); }