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:org.apache.openjpa.jdbc.sql.DBDictionary.java
/** * Return the preferred {@link Types} constant for the given * {@link JavaTypes} or {@link JavaSQLTypes} constant. *///from ww w . j a v a2 s . com public int getJDBCType(int metaTypeCode, boolean lob, int precis, int scale) { if (lob) { switch (metaTypeCode) { case JavaTypes.STRING: case JavaSQLTypes.ASCII_STREAM: case JavaSQLTypes.CHAR_STREAM: return getPreferredType(Types.CLOB); default: return getPreferredType(Types.BLOB); } } switch (metaTypeCode) { case JavaTypes.BOOLEAN: case JavaTypes.BOOLEAN_OBJ: return getPreferredType(Types.BIT); case JavaTypes.BYTE: case JavaTypes.BYTE_OBJ: return getPreferredType(Types.TINYINT); case JavaTypes.CHAR: case JavaTypes.CHAR_OBJ: if (storeCharsAsNumbers) return getPreferredType(Types.INTEGER); return getPreferredType(Types.CHAR); case JavaTypes.DOUBLE: case JavaTypes.DOUBLE_OBJ: if (precis > 0 || scale > 0) { return getPreferredType(Types.NUMERIC); } else { return getPreferredType(Types.DOUBLE); } case JavaTypes.FLOAT: case JavaTypes.FLOAT_OBJ: if (precis > 0 || scale > 0) { return getPreferredType(Types.NUMERIC); } else { return getPreferredType(Types.REAL); } case JavaTypes.INT: case JavaTypes.INT_OBJ: return getPreferredType(Types.INTEGER); case JavaTypes.LONG: case JavaTypes.LONG_OBJ: return getPreferredType(Types.BIGINT); case JavaTypes.SHORT: case JavaTypes.SHORT_OBJ: return getPreferredType(Types.SMALLINT); case JavaTypes.STRING: case JavaTypes.LOCALE: case JavaSQLTypes.ASCII_STREAM: case JavaSQLTypes.CHAR_STREAM: return getPreferredType(Types.VARCHAR); case JavaTypes.BIGINTEGER: if (storeLargeNumbersAsStrings) return getPreferredType(Types.VARCHAR); return getPreferredType(Types.BIGINT); case JavaTypes.BIGDECIMAL: if (storeLargeNumbersAsStrings) return getPreferredType(Types.VARCHAR); return getPreferredType(Types.NUMERIC); case JavaTypes.NUMBER: if (storeLargeNumbersAsStrings) return getPreferredType(Types.VARCHAR); return getPreferredType(Types.NUMERIC); case JavaTypes.CALENDAR: case JavaTypes.DATE: return getPreferredType(Types.TIMESTAMP); case JavaSQLTypes.SQL_ARRAY: return getPreferredType(Types.ARRAY); case JavaSQLTypes.BINARY_STREAM: case JavaSQLTypes.BLOB: case JavaSQLTypes.BYTES: return getPreferredType(Types.BLOB); case JavaSQLTypes.CLOB: return getPreferredType(Types.CLOB); case JavaSQLTypes.SQL_DATE: return getPreferredType(Types.DATE); case JavaSQLTypes.TIME: return getPreferredType(Types.TIME); case JavaSQLTypes.TIMESTAMP: return getPreferredType(Types.TIMESTAMP); default: return getPreferredType(Types.BLOB); } }
From source file:helma.objectmodel.db.NodeManager.java
private void setStatementValue(PreparedStatement stmt, int stmtNumber, Property p, int columnType) throws SQLException { if (p.getValue() == null) { stmt.setNull(stmtNumber, columnType); } else {/*w w w . j a va 2s. c o m*/ switch (columnType) { case Types.BIT: case Types.BOOLEAN: stmt.setBoolean(stmtNumber, p.getBooleanValue()); break; 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.LONGVARBINARY: case Types.VARBINARY: case Types.BINARY: case Types.BLOB: Object b = p.getJavaObjectValue(); if (b instanceof byte[]) { byte[] buf = (byte[]) b; try { stmt.setBytes(stmtNumber, buf); } catch (SQLException x) { ByteArrayInputStream bout = new ByteArrayInputStream(buf); stmt.setBinaryStream(stmtNumber, bout, buf.length); } } else { throw new SQLException( "expected byte[] for binary column '" + p.getName() + "', found " + b.getClass()); } break; 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.jumpmind.db.platform.AbstractDdlBuilder.java
/** * Generates the string representation of the given value. * * @param column// w ww .j a va 2 s .c om * The column * @param value * The value * @return The string representation */ protected String getValueAsString(Column column, Object value) { if (value == null) { return "NULL"; } StringBuffer result = new StringBuffer(); // TODO: Handle binary types (BINARY, VARBINARY, LONGVARBINARY, BLOB) switch (column.getMappedTypeCode()) { case Types.DATE: result.append(databaseInfo.getValueQuoteToken()); if (!(value instanceof String) && (getValueDateFormat() != null)) { // TODO: Can the format method handle java.sql.Date properly // ? result.append(getValueDateFormat().format(value)); } else { result.append(value.toString()); } result.append(databaseInfo.getValueQuoteToken()); break; case Types.TIME: result.append(databaseInfo.getValueQuoteToken()); if (!(value instanceof String) && (getValueTimeFormat() != null)) { // TODO: Can the format method handle java.sql.Date properly // ? result.append(getValueTimeFormat().format(value)); } else { result.append(value.toString()); } result.append(databaseInfo.getValueQuoteToken()); break; case Types.TIMESTAMP: result.append(databaseInfo.getValueQuoteToken()); // TODO: SimpleDateFormat does not support nano seconds so we // would // need a custom date formatter for timestamps result.append(value.toString()); result.append(databaseInfo.getValueQuoteToken()); break; case Types.REAL: case Types.NUMERIC: case Types.FLOAT: case Types.DOUBLE: case Types.DECIMAL: result.append(databaseInfo.getValueQuoteToken()); if (!(value instanceof String) && (getValueNumberFormat() != null)) { result.append(getValueNumberFormat().format(value)); } else { result.append(value.toString()); } result.append(databaseInfo.getValueQuoteToken()); break; default: result.append(databaseInfo.getValueQuoteToken()); result.append(escapeStringValue(value.toString())); result.append(databaseInfo.getValueQuoteToken()); break; } return result.toString(); }
From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java
/** * Returns the type name for the specific constant as defined * by {@link java.sql.Types}./*from w w w.j a va 2 s .co m*/ * * @param type the type * @return the name for the type */ public String getTypeName(int type) { switch (type) { case Types.ARRAY: return arrayTypeName; case Types.BIGINT: return bigintTypeName; case Types.BINARY: return binaryTypeName; case Types.BIT: return bitTypeName; case Types.BLOB: return blobTypeName; case Types.BOOLEAN: return booleanTypeName; case Types.CHAR: return charTypeName; case Types.CLOB: return clobTypeName; case Types.DATE: return dateTypeName; case Types.DECIMAL: return decimalTypeName; case Types.DISTINCT: return distinctTypeName; case Types.DOUBLE: return doubleTypeName; case Types.FLOAT: return floatTypeName; case Types.INTEGER: return integerTypeName; case Types.JAVA_OBJECT: return javaObjectTypeName; case Types.LONGVARBINARY: return longVarbinaryTypeName; case Types.LONGVARCHAR: return longVarcharTypeName; case Types.NULL: return nullTypeName; case Types.NUMERIC: return numericTypeName; case Types.OTHER: return otherTypeName; case Types.REAL: return realTypeName; case Types.REF: return refTypeName; case Types.SMALLINT: return smallintTypeName; case Types.STRUCT: return structTypeName; case Types.TIME: return timeTypeName; case Types.TIMESTAMP: return timestampTypeName; case Types.TINYINT: return tinyintTypeName; case Types.VARBINARY: return varbinaryTypeName; case Types.VARCHAR: return varcharTypeName; default: return otherTypeName; } }
From source file:org.apache.ddlutils.io.TestDatabaseIO.java
/** * Tests a database model with an index. *///from w ww. j a va 2 s. com public void testSingleIndex() 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" + " <index>\n" + " <index-column name='value'/>\n" + " </index>\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, false, 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" + " <index>\n" + " <index-column name=\"value\" />\n" + " </index>\n" + " </table>\n" + "</database>\n", model); }
From source file:org.apache.ddlutils.io.TestDatabaseIO.java
/** * Tests a database model with an index with two columns. *//* ww w. j a v a 2 s.c o m*/ public void testIndexWithTwoColumns() 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" + " <index>\n" + " <index-column name='when'/>\n" + " <index-column name='id'/>\n" + " </index>\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, false, 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" + " <index>\n" + " <index-column name=\"when\" />\n" + " <index-column name=\"id\" />\n" + " </index>\n" + " </table>\n" + "</database>\n", model); }
From source file:ua.utility.kfsdbupgrade.App.java
/** * @param type//from w ww .j a va2s. com * <code>int</code> of a {@link Types} value * @return <code>true</code> if <code>type</code> is one of the following: * <ul> * <li>{@link Types#BIGINT}</li> * <li>{@link Types#BINARY}</li> * <li>{@link Types#DECIMAL}</li> * <li>{@link Types#DOUBLE}</li> * <li>{@link Types#FLOAT}</li> * <li>{@link Types#INTEGER}</li> * <li>{@link Types#NUMERIC}</li> * <li>{@link Types#REAL}</li> * <li>{@link Types#SMALLINT}</li> * <li>{@link Types#TINYINT}</li> * </ul> * <p> * , <code>false</code> otherwise. */ private boolean isNumericJavaType(int type) { return ((type == java.sql.Types.BIGINT) || (type == java.sql.Types.BINARY) || (type == java.sql.Types.DECIMAL) || (type == java.sql.Types.DOUBLE) || (type == java.sql.Types.FLOAT) || (type == java.sql.Types.INTEGER) || (type == java.sql.Types.NUMERIC) || (type == java.sql.Types.REAL) || (type == java.sql.Types.SMALLINT) || (type == java.sql.Types.TINYINT)); }
From source file:fll.db.Queries.java
/** * Compute the total scores for all entered subjective scores. * /* w ww.j ava 2 s.co m*/ * @param connection * @throws SQLException */ @SuppressFBWarnings(value = { "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING" }, justification = "Category determines table name") private static void updateSubjectiveScoreTotals(final ChallengeDescription description, final Connection connection, final int tournament) throws SQLException { PreparedStatement updatePrep = null; PreparedStatement selectPrep = null; ResultSet rs = null; try { // Subjective --- for (final ScoreCategory subjectiveElement : description.getSubjectiveCategories()) { final String categoryName = subjectiveElement.getName(); // build up the SQL updatePrep = connection.prepareStatement("UPDATE "// + categoryName // + " SET ComputedTotal = ? WHERE TeamNumber = ? AND Tournament = ? AND Judge = ?"); selectPrep = connection.prepareStatement("SELECT * FROM " // + categoryName // + " WHERE Tournament = ?"); selectPrep.setInt(1, tournament); updatePrep.setInt(3, tournament); rs = selectPrep.executeQuery(); while (rs.next()) { final int teamNumber = rs.getInt("TeamNumber"); final TeamScore teamScore = new DatabaseTeamScore(teamNumber, rs); final double computedTotal; if (teamScore.isNoShow()) { computedTotal = Double.NaN; } else { computedTotal = subjectiveElement.evaluate(teamScore); } if (Double.isNaN(computedTotal)) { updatePrep.setNull(1, Types.DOUBLE); } else { updatePrep.setDouble(1, computedTotal); } updatePrep.setInt(2, teamNumber); final String judge = rs.getString("Judge"); updatePrep.setString(4, judge); updatePrep.executeUpdate(); } rs.close(); updatePrep.close(); selectPrep.close(); } } finally { SQLFunctions.close(rs); SQLFunctions.close(updatePrep); SQLFunctions.close(selectPrep); } }
From source file:org.apache.ddlutils.io.TestDatabaseIO.java
/** * Tests a database model with an index with a name. *///w ww .j av a 2s . c o m public void testIndexWithName() 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" + " <index name='The Index'>\n" + " <index-column name='value'/>\n" + " </index>\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", false, 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" + " <index name=\"The Index\">\n" + " <index-column name=\"value\" />\n" + " </index>\n" + " </table>\n" + "</database>\n", model); }
From source file:org.apache.openjpa.jdbc.sql.DBDictionary.java
/** * Return a SQL string to act as a placeholder for the given column. *///from ww w . j a v a 2 s .c o m public String getPlaceholderValueString(Column col) { switch (col.getType()) { case Types.BIGINT: case Types.BIT: case Types.INTEGER: case Types.NUMERIC: case Types.SMALLINT: case Types.TINYINT: return "0"; case Types.CHAR: return (storeCharsAsNumbers) ? "0" : "' '"; case Types.CLOB: case Types.LONGVARCHAR: case Types.VARCHAR: return "''"; case Types.DATE: return ZERO_DATE_STR; case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: return "0.0"; case Types.TIME: return ZERO_TIME_STR; case Types.TIMESTAMP: return ZERO_TIMESTAMP_STR; default: return "NULL"; } }