List of usage examples for java.sql Types DOUBLE
int DOUBLE
To view the source code for java.sql Types DOUBLE.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DOUBLE
.
From source file:fll.db.Queries.java
/** * Compute the total scores for all entered performance scores. Uses both * verified and unverified scores./*from w ww .j a va2 s . c o m*/ * * @param connection connection to the database * @param tournament the tournament to update scores for. * @throws SQLException */ private static void updatePerformanceScoreTotals(final ChallengeDescription description, final Connection connection, final int tournament) throws SQLException { PreparedStatement updatePrep = null; PreparedStatement selectPrep = null; ResultSet rs = null; try { // build up the SQL updatePrep = connection.prepareStatement( "UPDATE Performance SET ComputedTotal = ? WHERE TeamNumber = ? AND Tournament = ? AND RunNumber = ?"); updatePrep.setInt(3, tournament); selectPrep = connection.prepareStatement("SELECT * FROM Performance WHERE Tournament = ?"); selectPrep.setInt(1, tournament); final PerformanceScoreCategory performanceElement = description.getPerformance(); final double minimumPerformanceScore = performanceElement.getMinimumScore(); rs = selectPrep.executeQuery(); while (rs.next()) { if (!rs.getBoolean("Bye")) { final int teamNumber = rs.getInt("TeamNumber"); final int runNumber = rs.getInt("RunNumber"); final TeamScore teamScore = new DatabaseTeamScore(teamNumber, runNumber, rs); final double computedTotal; if (teamScore.isNoShow()) { computedTotal = Double.NaN; } else { computedTotal = performanceElement.evaluate(teamScore); } if (LOGGER.isTraceEnabled()) { LOGGER.trace("Updating performance score for " + teamNumber + " run: " + runNumber + " total: " + computedTotal); } if (!Double.isNaN(computedTotal)) { updatePrep.setDouble(1, Math.max(computedTotal, minimumPerformanceScore)); } else { updatePrep.setNull(1, Types.DOUBLE); } updatePrep.setInt(2, teamNumber); updatePrep.setInt(4, runNumber); updatePrep.executeUpdate(); } } rs.close(); updatePrep.close(); selectPrep.close(); } finally { SQLFunctions.close(rs); SQLFunctions.close(updatePrep); SQLFunctions.close(selectPrep); } }
From source file:edu.jhuapl.openessence.datasource.jdbc.entry.JdbcOeDataEntrySource.java
/** * Sets arguments of the proper type on a PreparedSatement * * @param pStmt prepared statement on which to set arguments * @param dimIds dimension ids that map to columns on the prepared statement * @param valueList values to set for the paramenters on the prepared statement * @param valueMap dimIds mapped to values to set for the paramenters on the prepared statement * @throws SQLException if error occurs while processing the prepared statement * @throws OeDataSourceException if error occurs converting value to it's sql type *//* ww w .ja v a 2 s. c o m*/ protected void setArgumentsOnSqlType(PreparedStatement pStmt, List<String> dimIds, List<Object> valueList, Map<String, Object> valueMap) throws SQLException, OeDataSourceException { if ((valueList == null && valueMap == null) || (valueList != null && valueMap != null)) { throw new OeDataSourceException("Invalid value lists. Only one form of the list can be provided."); } int argCount = 0; Object val; boolean isValueList = (valueList != null); for (String dimId : dimIds) { Dimension dim = getEditDimension(dimId); FieldType sqlType = dim.getSqlType(); if (isValueList) { val = valueList.get(argCount); } else { val = valueMap.get(dimId); } try { argCount++; switch (sqlType) { case DATE_TIME: pStmt.setObject(argCount, DataTypeConversionHelper.convert2SqlTimestampType(val), Types.TIMESTAMP); continue; case DATE: pStmt.setObject(argCount, DataTypeConversionHelper.convert2SqlType(val), Types.DATE); continue; case BOOLEAN: pStmt.setObject(argCount, DataTypeConversionHelper.convert2SqlType(val), Types.BOOLEAN); continue; case FLOAT: pStmt.setObject(argCount, DataTypeConversionHelper.convert2SqlType(val), Types.FLOAT); continue; case DOUBLE: pStmt.setObject(argCount, DataTypeConversionHelper.convert2SqlType(val), Types.DOUBLE); continue; case INTEGER: pStmt.setObject(argCount, DataTypeConversionHelper.convert2SqlType(val), Types.INTEGER); continue; case LONG: pStmt.setObject(argCount, DataTypeConversionHelper.convert2SqlType(val), Types.BIGINT); continue; case TEXT: pStmt.setObject(argCount, DataTypeConversionHelper.convert2SqlType(val), Types.VARCHAR); continue; default: throw new AssertionError("Unexpected sqlType " + sqlType + "."); } } catch (OeDataSourceException e) { throw new SQLException("Error occured converting value \"" + val + "\" to its sql type.", e); } } }
From source file:org.apache.ddlutils.io.TestDatabaseIO.java
/** * Tests a database model with an unique index. *///from w w w.jav a2 s.co m public void testSingleUniqueIndex() throws Exception { Database model = readModel("<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" + " <table name='TableWithIndex'>\n" + " <column name='id'\n" + " type='DOUBLE'\n" + " primaryKey='true'\n" + " required='true'/>\n" + " <column name='value'\n" + " type='SMALLINT'\n" + " default='1'/>\n" + " <unique>\n" + " <unique-column name='value'/>\n" + " </unique>\n" + " </table>\n" + "</database>"); assertEquals("test", model.getName()); assertEquals(1, model.getTableCount()); Table table = model.getTable(0); assertEquals("TableWithIndex", null, 2, 1, 0, 0, 1, table); assertEquals("id", Types.DOUBLE, 0, 0, null, null, null, true, true, false, table.getColumn(0)); assertEquals("value", Types.SMALLINT, 0, 0, "1", null, null, false, false, false, table.getColumn(1)); Index index = table.getIndex(0); assertEquals(null, true, 1, index); assertEquals(table.getColumn(1), null, index.getColumn(0)); assertEquals("<?xml version='1.0' encoding='UTF-8'?>\n" + "<database xmlns=\"" + DatabaseIO.DDLUTILS_NAMESPACE + "\" name=\"test\">\n" + " <table name=\"TableWithIndex\">\n" + " <column name=\"id\" primaryKey=\"true\" required=\"true\" type=\"DOUBLE\" autoIncrement=\"false\" />\n" + " <column name=\"value\" primaryKey=\"false\" required=\"false\" type=\"SMALLINT\" default=\"1\" autoIncrement=\"false\" />\n" + " <unique>\n" + " <unique-column name=\"value\" />\n" + " </unique>\n" + " </table>\n" + "</database>\n", model); }
From source file:org.apache.ddlutils.io.TestDatabaseIO.java
/** * Tests a database model with an unique index with two columns. */// w ww . j a v a 2 s . c om public void testUniqueIndexWithTwoColumns() throws Exception { Database model = readModel("<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" + " <table name='TableWithIndex'>\n" + " <column name='id'\n" + " type='DOUBLE'\n" + " primaryKey='true'\n" + " required='true'/>\n" + " <column name='when'\n" + " type='TIMESTAMP'\n" + " required='true'/>\n" + " <column name='value'\n" + " type='SMALLINT'\n" + " default='1'/>\n" + " <unique>\n" + " <unique-column name='when'/>\n" + " <unique-column name='id'/>\n" + " </unique>\n" + " </table>\n" + "</database>"); assertEquals("test", model.getName()); assertEquals(1, model.getTableCount()); Table table = model.getTable(0); assertEquals("TableWithIndex", null, 3, 1, 0, 0, 1, table); assertEquals("id", Types.DOUBLE, 0, 0, null, null, null, true, true, false, table.getColumn(0)); assertEquals("when", Types.TIMESTAMP, 0, 0, null, null, null, false, true, false, table.getColumn(1)); assertEquals("value", Types.SMALLINT, 0, 0, "1", null, null, false, false, false, table.getColumn(2)); Index index = table.getIndex(0); assertEquals(null, true, 2, index); assertEquals(table.getColumn(1), null, index.getColumn(0)); assertEquals(table.getColumn(0), null, index.getColumn(1)); assertEquals("<?xml version='1.0' encoding='UTF-8'?>\n" + "<database xmlns=\"" + DatabaseIO.DDLUTILS_NAMESPACE + "\" name=\"test\">\n" + " <table name=\"TableWithIndex\">\n" + " <column name=\"id\" primaryKey=\"true\" required=\"true\" type=\"DOUBLE\" autoIncrement=\"false\" />\n" + " <column name=\"when\" primaryKey=\"false\" required=\"true\" type=\"TIMESTAMP\" autoIncrement=\"false\" />\n" + " <column name=\"value\" primaryKey=\"false\" required=\"false\" type=\"SMALLINT\" default=\"1\" autoIncrement=\"false\" />\n" + " <unique>\n" + " <unique-column name=\"when\" />\n" + " <unique-column name=\"id\" />\n" + " </unique>\n" + " </table>\n" + "</database>\n", model); }
From source file:axiom.objectmodel.db.NodeManager.java
/** * Create a new Node from a ResultSet.//from www.j a v a 2s .c o m */ public Node createNode(DbMapping dbm, ResultSet rs, DbColumn[] columns, int offset) throws SQLException, IOException, ClassNotFoundException { HashMap propBuffer = new HashMap(); String id = null; String name = null; String protoName = dbm.getTypeName(); DbMapping dbmap = dbm; Node node = new Node(); for (int i = 0; i < columns.length; i++) { // set prototype? if (columns[i].isPrototypeField()) { protoName = rs.getString(i + 1 + offset); if (protoName != null) { dbmap = getDbMapping(protoName); if (dbmap == null) { // invalid prototype name! app.logError(ErrorReporter.errorMsg(this.getClass(), "createNode") + "Invalid prototype name: " + protoName + " - using default"); dbmap = dbm; protoName = dbmap.getTypeName(); } } } // set id? if (columns[i].isIdField()) { id = rs.getString(i + 1 + offset); // if id == null, the object doesn't actually exist - return null if (id == null) { return null; } } // set name? if (columns[i].isNameField()) { name = rs.getString(i + 1 + offset); } Property newprop = new Property(node); switch (columns[i].getType()) { case Types.BIT: newprop.setBooleanValue(rs.getBoolean(i + 1 + offset)); break; case Types.TINYINT: case Types.BIGINT: case Types.SMALLINT: case Types.INTEGER: newprop.setIntegerValue(rs.getLong(i + 1 + offset)); break; case Types.REAL: case Types.FLOAT: case Types.DOUBLE: newprop.setFloatValue(rs.getDouble(i + 1 + offset)); break; case Types.DECIMAL: case Types.NUMERIC: BigDecimal num = rs.getBigDecimal(i + 1 + offset); if (num == null) { break; } if (num.scale() > 0) { newprop.setFloatValue(num.doubleValue()); } else { newprop.setIntegerValue(num.longValue()); } break; case Types.VARBINARY: case Types.BINARY: // newprop.setStringValue(rs.getString(i+1+offset)); newprop.setJavaObjectValue(rs.getBytes(i + 1 + offset)); break; case Types.LONGVARBINARY: { InputStream in = rs.getBinaryStream(i + 1 + offset); if (in == null) { break; } ByteArrayOutputStream bout = new ByteArrayOutputStream(); byte[] buffer = new byte[2048]; int read; while ((read = in.read(buffer)) > -1) { bout.write(buffer, 0, read); } newprop.setJavaObjectValue(bout.toByteArray()); } break; case Types.LONGVARCHAR: try { newprop.setStringValue(rs.getString(i + 1 + offset)); } catch (SQLException x) { Reader in = rs.getCharacterStream(i + 1 + offset); char[] buffer = new char[2048]; int read = 0; int r; while ((r = in.read(buffer, read, buffer.length - read)) > -1) { read += r; if (read == buffer.length) { // grow input buffer char[] newBuffer = new char[buffer.length * 2]; System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); buffer = newBuffer; } } newprop.setStringValue(new String(buffer, 0, read)); } break; case Types.CHAR: case Types.VARCHAR: case Types.OTHER: newprop.setStringValue(rs.getString(i + 1 + offset)); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: newprop.setDateValue(rs.getTimestamp(i + 1 + offset)); break; case Types.NULL: newprop.setStringValue(null); break; case Types.CLOB: Clob cl = rs.getClob(i + 1 + offset); if (cl == null) { newprop.setStringValue(null); break; } char[] c = new char[(int) cl.length()]; Reader isr = cl.getCharacterStream(); isr.read(c); newprop.setStringValue(String.copyValueOf(c)); break; default: newprop.setStringValue(rs.getString(i + 1 + offset)); break; } if (rs.wasNull()) { newprop.setStringValue(null); } propBuffer.put(columns[i].getName(), newprop); // mark property as clean, since it's fresh from the db newprop.dirty = false; } if (id == null) { return null; } Hashtable propMap = new Hashtable(); DbColumn[] columns2 = dbmap.getColumns(); for (int i = 0; i < columns2.length; i++) { Relation rel = columns2[i].getRelation(); if (rel != null && (rel.reftype == Relation.PRIMITIVE || rel.reftype == Relation.REFERENCE)) { Property prop = (Property) propBuffer.get(columns2[i].getName()); if (prop == null) { continue; } prop.setName(rel.propName); // if the property is a pointer to another node, change the property type to NODE if ((rel.reftype == Relation.REFERENCE) && rel.usesPrimaryKey()) { // FIXME: References to anything other than the primary key are not supported prop.convertToNodeReference(rel.otherType, this.app.getCurrentRequestEvaluator().getLayer()); } propMap.put(rel.propName.toLowerCase(), prop); } } node.init(dbmap, id, name, protoName, propMap, safe); return node; }
From source file:org.apache.ddlutils.io.TestDatabaseIO.java
/** * Tests a database model with an unique index with a name. *//*from ww w. jav a2 s. co m*/ public void testUniqueIndexWithName() throws Exception { Database model = readModel("<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='test'>\n" + " <table name='TableWithIndex'>\n" + " <column name='id'\n" + " type='DOUBLE'\n" + " primaryKey='true'\n" + " required='true'/>\n" + " <column name='value'\n" + " type='SMALLINT'\n" + " default='1'/>\n" + " <unique name='The Index'>\n" + " <unique-column name='value'/>\n" + " </unique>\n" + " </table>\n" + "</database>"); assertEquals("test", model.getName()); assertEquals(1, model.getTableCount()); Table table = model.getTable(0); assertEquals("TableWithIndex", null, 2, 1, 0, 0, 1, table); assertEquals("id", Types.DOUBLE, 0, 0, null, null, null, true, true, false, table.getColumn(0)); assertEquals("value", Types.SMALLINT, 0, 0, "1", null, null, false, false, false, table.getColumn(1)); Index index = table.getIndex(0); assertEquals("The Index", true, 1, index); assertEquals(table.getColumn(1), null, index.getColumn(0)); assertEquals("<?xml version='1.0' encoding='UTF-8'?>\n" + "<database xmlns=\"" + DatabaseIO.DDLUTILS_NAMESPACE + "\" name=\"test\">\n" + " <table name=\"TableWithIndex\">\n" + " <column name=\"id\" primaryKey=\"true\" required=\"true\" type=\"DOUBLE\" autoIncrement=\"false\" />\n" + " <column name=\"value\" primaryKey=\"false\" required=\"false\" type=\"SMALLINT\" default=\"1\" autoIncrement=\"false\" />\n" + " <unique name=\"The Index\">\n" + " <unique-column name=\"value\" />\n" + " </unique>\n" + " </table>\n" + "</database>\n", model); }
From source file:org.wso2.carbon.dataservices.core.description.query.SQLQuery.java
private void setDoubleValue(int queryType, String value, String paramType, PreparedStatement sqlQuery, int i) throws SQLException { Double val = null; if (value != null) { val = Double.parseDouble(value); }/*from w w w .ja v a2 s. c o m*/ if (QueryTypes.IN.equals(paramType)) { if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) { if (value == null) { sqlQuery.setNull(i + 1, java.sql.Types.DOUBLE); } else { sqlQuery.setDouble(i + 1, val); } } else { if (value == null) { ((CallableStatement) sqlQuery).setNull(i + 1, java.sql.Types.DOUBLE); } else { ((CallableStatement) sqlQuery).setDouble(i + 1, val); } } } else if (QueryTypes.INOUT.equals(paramType)) { if (value == null) { ((CallableStatement) sqlQuery).setNull(i + 1, java.sql.Types.DOUBLE); } else { ((CallableStatement) sqlQuery).setDouble(i + 1, val); } ((CallableStatement) sqlQuery).registerOutParameter(i + 1, java.sql.Types.DOUBLE); } else { ((CallableStatement) sqlQuery).registerOutParameter(i + 1, java.sql.Types.DOUBLE); } }
From source file:axiom.objectmodel.db.NodeManager.java
private void setStatementValues(PreparedStatement stmt, int stmtNumber, Property p, int columnType) throws SQLException { if (p.getValue() == null) { stmt.setNull(stmtNumber, columnType); } else {//from ww w . j a va 2 s. c o m switch (columnType) { case Types.BIT: case Types.TINYINT: case Types.BIGINT: case Types.SMALLINT: case Types.INTEGER: stmt.setLong(stmtNumber, p.getIntegerValue()); break; case Types.REAL: case Types.FLOAT: case Types.DOUBLE: case Types.NUMERIC: case Types.DECIMAL: stmt.setDouble(stmtNumber, p.getFloatValue()); break; case Types.VARBINARY: case Types.BINARY: case Types.BLOB: stmt.setString(stmtNumber, p.getStringValue()); break; case Types.LONGVARBINARY: case Types.LONGVARCHAR: try { stmt.setString(stmtNumber, p.getStringValue()); } catch (SQLException x) { String str = p.getStringValue(); Reader r = new StringReader(str); stmt.setCharacterStream(stmtNumber, r, str.length()); } break; case Types.CLOB: String val = p.getStringValue(); Reader isr = new StringReader(val); stmt.setCharacterStream(stmtNumber, isr, val.length()); break; case Types.CHAR: case Types.VARCHAR: case Types.OTHER: stmt.setString(stmtNumber, p.getStringValue()); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: stmt.setTimestamp(stmtNumber, p.getTimestampValue()); break; case Types.NULL: stmt.setNull(stmtNumber, 0); break; default: stmt.setString(stmtNumber, p.getStringValue()); break; } } }
From source file:org.apache.ddlutils.platform.PlatformImplBase.java
/** * This is the core method to retrieve a value for a column from a result set. Its primary * purpose is to call the appropriate method on the result set, and to provide an extension * point where database-specific implementations can change this behavior. * // w ww. j a va 2 s . com * @param resultSet The result set to extract the value from * @param columnName The name of the column; can be <code>null</code> in which case the * <code>columnIdx</code> will be used instead * @param columnIdx The index of the column's value in the result set; is only used if * <code>columnName</code> is <code>null</code> * @param jdbcType The jdbc type to extract * @return The value * @throws SQLException If an error occurred while accessing the result set */ protected Object extractColumnValue(ResultSet resultSet, String columnName, int columnIdx, int jdbcType) throws SQLException { boolean useIdx = (columnName == null); Object value; switch (jdbcType) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: value = useIdx ? resultSet.getString(columnIdx) : resultSet.getString(columnName); break; case Types.NUMERIC: case Types.DECIMAL: value = useIdx ? resultSet.getBigDecimal(columnIdx) : resultSet.getBigDecimal(columnName); break; case Types.BIT: case Types.BOOLEAN: value = new Boolean(useIdx ? resultSet.getBoolean(columnIdx) : resultSet.getBoolean(columnName)); break; case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: value = new Integer(useIdx ? resultSet.getInt(columnIdx) : resultSet.getInt(columnName)); break; case Types.BIGINT: value = new Long(useIdx ? resultSet.getLong(columnIdx) : resultSet.getLong(columnName)); break; case Types.REAL: value = new Float(useIdx ? resultSet.getFloat(columnIdx) : resultSet.getFloat(columnName)); break; case Types.FLOAT: case Types.DOUBLE: value = new Double(useIdx ? resultSet.getDouble(columnIdx) : resultSet.getDouble(columnName)); break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: value = useIdx ? resultSet.getBytes(columnIdx) : resultSet.getBytes(columnName); break; case Types.DATE: value = useIdx ? resultSet.getDate(columnIdx) : resultSet.getDate(columnName); break; case Types.TIME: value = useIdx ? resultSet.getTime(columnIdx) : resultSet.getTime(columnName); break; case Types.TIMESTAMP: value = useIdx ? resultSet.getTimestamp(columnIdx) : resultSet.getTimestamp(columnName); break; case Types.CLOB: Clob clob = useIdx ? resultSet.getClob(columnIdx) : resultSet.getClob(columnName); if (clob == null) { value = null; } else { long length = clob.length(); if (length > Integer.MAX_VALUE) { value = clob; } else if (length == 0) { // the javadoc is not clear about whether Clob.getSubString // can be used with a substring length of 0 // thus we do the safe thing and handle it ourselves value = ""; } else { value = clob.getSubString(1l, (int) length); } } break; case Types.BLOB: Blob blob = useIdx ? resultSet.getBlob(columnIdx) : resultSet.getBlob(columnName); if (blob == null) { value = null; } else { long length = blob.length(); if (length > Integer.MAX_VALUE) { value = blob; } else if (length == 0) { // the javadoc is not clear about whether Blob.getBytes // can be used with for 0 bytes to be copied // thus we do the safe thing and handle it ourselves value = new byte[0]; } else { value = blob.getBytes(1l, (int) length); } } break; case Types.ARRAY: value = useIdx ? resultSet.getArray(columnIdx) : resultSet.getArray(columnName); break; case Types.REF: value = useIdx ? resultSet.getRef(columnIdx) : resultSet.getRef(columnName); break; default: value = useIdx ? resultSet.getObject(columnIdx) : resultSet.getObject(columnName); break; } return resultSet.wasNull() ? null : value; }
From source file:com.mirth.connect.donkey.server.data.jdbc.JdbcDao.java
private static String sqlTypeToString(int sqlType) { switch (sqlType) { case Types.ARRAY: return "ARRAY"; case Types.BIGINT: return "BIGINT"; case Types.BINARY: return "BINARY"; case Types.BIT: return "BIT"; case Types.BLOB: return "BLOB"; case Types.BOOLEAN: return "BOOLEAN"; case Types.CHAR: return "CHAR"; case Types.CLOB: return "CLOB"; case Types.DATALINK: return "DATALINK"; case Types.DATE: return "DATE"; case Types.DECIMAL: return "DECIMAL"; case Types.DISTINCT: return "DISTINCT"; case Types.DOUBLE: return "DOUBLE"; case Types.FLOAT: return "FLOAT"; case Types.INTEGER: return "INTEGER"; case Types.JAVA_OBJECT: return "JAVA_OBJECT"; case Types.LONGNVARCHAR: return "LONGNVARCHAR"; case Types.LONGVARBINARY: return "LONGVARBINARY"; case Types.LONGVARCHAR: return "LONGVARCHAR"; case Types.NCHAR: return "NCHAR"; case Types.NCLOB: return "NCLOB"; case Types.NULL: return "NULL"; case Types.NUMERIC: return "NUMERIC"; case Types.NVARCHAR: return "NVARCHAR"; case Types.OTHER: return "OTHER"; case Types.REAL: return "REAL"; case Types.REF: return "REF"; case Types.ROWID: return "ROWID"; case Types.SMALLINT: return "SMALLINT"; case Types.SQLXML: return "SQLXML"; case Types.STRUCT: return "STRUCT"; case Types.TIME: return "TIME"; case Types.TIMESTAMP: return "TIMESTAMP"; case Types.TINYINT: return "TINYINT"; case Types.VARBINARY: return "VARBINARY"; case Types.VARCHAR: return "VARCHAR"; default://from www .j av a 2 s .c om return "UNKNOWN"; } }