List of usage examples for java.sql Types NUMERIC
int NUMERIC
To view the source code for java.sql Types NUMERIC.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NUMERIC
.
From source file:com.flexive.ejb.beans.structure.AssignmentEngineBean.java
/** * Find all (directly) derived assignments and flag them as 'regular' assignments and set them as new base * * @param con an open and valid connection * @param sql string builder/*from w w w.j a va 2 s .c o m*/ * @param assignments the assignments to 'break' * @throws FxNotFoundException on errors * @throws FxInvalidParameterException on errors * @throws java.sql.SQLException on errors */ private void breakAssignmentInheritance(Connection con, StringBuilder sql, FxAssignment... assignments) throws SQLException, FxNotFoundException, FxInvalidParameterException { sql.setLength(0); sql.append("UPDATE ").append(TBL_STRUCT_ASSIGNMENTS).append(" SET BASE=? WHERE BASE=?"); // AND TYPEDEF=?"); PreparedStatement ps = null; try { ps = con.prepareStatement(sql.toString()); ps.setNull(1, Types.NUMERIC); for (FxAssignment as : assignments) { ps.setLong(2, as.getId()); int count = 0; //'toplevel' fix // for(FxType types: assignment.getAssignedType().getDerivedTypes() ) { // ps.setLong(3, types.getId()); count += ps.executeUpdate(); // } if (count > 0) LOG.info("Updated " + count + " assignments to become the new base assignment"); /* sql.setLength(0); //now fix 'deeper' inherited assignments for(FxType types: assignment.getAssignedType().getDerivedTypes() ) { for( FxType subderived: types.getDerivedTypes()) _fixSubInheritance(ps, subderived, types.getAssignment(assignment.getXPath()).getId(), assignment.getId()); }*/ } ps.close(); sql.setLength(0); } finally { Database.closeObjects(AssignmentEngineBean.class, null, ps); } }
From source file:lasige.steeldb.jdbc.BFTRowSet.java
/** * Indicates whether the given SQL data type is a numberic type. * * @param type one of the constants from <code>java.sql.Types</code> * @return <code>true</code> if the given type is <code>NUMERIC</code>,' * <code>DECIMAL</code>, <code>BIT</code>, <code>TINYINT</code>, * <code>SMALLINT</code>, <code>INTEGER</code>, <code>BIGINT</code>, * <code>REAL</code>, <code>DOUBLE</code>, or <code>FLOAT</code>; * <code>false</code> otherwise *//* w w w .j ava 2s.c om*/ private boolean isNumeric(int type) { switch (type) { case java.sql.Types.NUMERIC: case java.sql.Types.DECIMAL: case java.sql.Types.BIT: case java.sql.Types.TINYINT: case java.sql.Types.SMALLINT: case java.sql.Types.INTEGER: case java.sql.Types.BIGINT: case java.sql.Types.REAL: case java.sql.Types.DOUBLE: case java.sql.Types.FLOAT: 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 mapping for the specified SQL target data type. * The conversion must be to a string or numeric type, but there are no * restrictions on the type to be converted. 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>NUMERIC</code>, * <code>DECIMAL</code>, <code>BIT</code>, <code>TINYINT</code>, * <code>SMALLINT</code>, <code>INTEGER</code>, <code>BIGINT</code>, * <code>REAL</code>, <code>DOUBLE</code>, <code>FLOAT</code>, * <code>VARCHAR</code>, <code>LONGVARCHAR</code>, or <code>CHAR</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 * numeric types in <code>java.sql.Types</code> *//*from ww w . j ava 2 s.co m*/ private Object convertNumeric(Object srcObj, int srcType, int trgType) throws SQLException { if (srcType == trgType) { return srcObj; } if (isNumeric(trgType) == false && isString(trgType) == false) { throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString() + trgType); } try { switch (trgType) { case java.sql.Types.BIT: Integer i = new Integer(srcObj.toString().trim()); return i.equals(new Integer((int) 0)) ? new Boolean(false) : new Boolean(true); case java.sql.Types.TINYINT: return new Byte(srcObj.toString().trim()); case java.sql.Types.SMALLINT: return new Short(srcObj.toString().trim()); case java.sql.Types.INTEGER: return new Integer(srcObj.toString().trim()); case java.sql.Types.BIGINT: return new Long(srcObj.toString().trim()); case java.sql.Types.NUMERIC: case java.sql.Types.DECIMAL: return new BigDecimal(srcObj.toString().trim()); case java.sql.Types.REAL: case java.sql.Types.FLOAT: return new Float(srcObj.toString().trim()); case java.sql.Types.DOUBLE: return new Double(srcObj.toString().trim()); 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() + trgType); } } catch (NumberFormatException ex) { throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString() + trgType); } }
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>java.math.BigDecimal</code> object. * <P>//from www . j ava 2 s . co m * This method updates a column value in 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. * * @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, or (3) this rowset is * <code>ResultSet.CONCUR_READ_ONLY</code> */ public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { // sanity check. checkIndex(columnIndex); // make sure the cursor is on a valid row checkCursor(); Object obj = convertNumeric(x, java.sql.Types.NUMERIC, RowSetMD.getColumnType(columnIndex)); getCurrentRow().setColumnObject(columnIndex, obj); }
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>Object</code> value. The <code>scale</code> parameter indicates * the number of digits to the right of the decimal point and is ignored * if the new column value is not a type that will be mapped to an SQL * <code>DECIMAL</code> or <code>NUMERIC</code> value. * <P>// w ww. j a v a 2 s . co m * 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. * * @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 * @param scale the number of digits to the right of the decimal point (for * <code>DECIMAL</code> and <code>NUMERIC</code> types only) * @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, or (3) this rowset is * <code>ResultSet.CONCUR_READ_ONLY</code> */ public void updateObject(int columnIndex, Object x, int scale) throws SQLException { // sanity check. checkIndex(columnIndex); // make sure the cursor is on a valid row checkCursor(); int type = RowSetMD.getColumnType(columnIndex); if (type == Types.DECIMAL || type == Types.NUMERIC) { ((java.math.BigDecimal) x).setScale(scale); } getCurrentRow().setColumnObject(columnIndex, x); }