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:com.nextep.designer.sqlclient.ui.connectors.SQLResultConnector.java
private void initializeTable(ISQLQuery query, long executionTime, INextepMetadata md) { colMaxWidth = new int[md.getColumnCount() + 1]; // Checking columns to display int displayedColumns = query.getDisplayedColumnsCount(); if (displayedColumns <= 0) { displayedColumns = md.getColumnCount(); }/*w w w. j av a2 s . c om*/ for (int i = 1; i <= displayedColumns; i++) { final String colName = md.getColumnName(i); // final int colPrecision = md.getPrecision(index); final int colType = md.getColumnType(i); final int colIndex = i - 1; if (!sqlView.isDisposed()) { TableColumn c = new TableColumn(sqlView, SWT.NONE); c.setText(colName); c.setWidth(colName.length() * 8); c.addListener(SWT.Selection, comparator); colMaxWidth[colIndex] = c.getWidth(); SQLResultLabelProvider lblProvider = new SQLResultLabelProvider(this, colIndex); final TableViewerColumn viewerCol = new TableViewerColumn(sqlViewer, c); viewerCol.setLabelProvider(lblProvider); // Registering column comparator switch (colType) { case Types.BIGINT: case Types.BIT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.INTEGER: case Types.NUMERIC: case Types.REAL: case Types.SMALLINT: case Types.TINYINT: c.setData(SQLResultViewerComparator.KEY_COMPARATOR, new NumberComparator()); // Setting our deserializer which can produce number from string c.setData(KEY_DESERIALIZER, NUMBER_DESERIALIZER); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: // Defines validation so that user will be notified about problems c.setData(KEY_CELL_VALIDATOR, DATE_VALIDATOR); // Setting our deserializer which can produce date from string c.setData(KEY_DESERIALIZER, DATE_DESERIALIZER); c.setData(SQLResultViewerComparator.KEY_COMPARATOR, new DateComparator()); break; default: c.setData(KEY_DESERIALIZER, STRING_DESERIALIZER); c.setData(SQLResultViewerComparator.KEY_COMPARATOR, new StringComparator()); } } } registerCellEditors(); setStatusLabel(MessageFormat.format(SQLClientMessages.getString("sql.executionTime"), executionTime), false); sqlViewer.setInput(query.getResult()); }
From source file:org.jumpmind.symmetric.db.derby.DerbyFunctions.java
public static String getPrimaryKeyWhereString(String[] pkColumnNames, ResultSet rs) throws SQLException { final String AND = " and "; ResultSetMetaData metaData = rs.getMetaData(); StringBuilder b = new StringBuilder(); for (int i = 0; i < pkColumnNames.length; i++) { String columnName = pkColumnNames[i]; int index = findColumnIndex(metaData, columnName); int type = metaData.getColumnType(index); if (type != Types.BINARY && type != Types.BLOB && type != Types.LONGVARBINARY && type != Types.VARBINARY) { b.append("\"").append(columnName).append("\"="); switch (type) { case Types.BIT: case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: case Types.FLOAT: case Types.REAL: case Types.DOUBLE: case Types.NUMERIC: case Types.DECIMAL: case Types.BOOLEAN: b.append(rs.getObject(index)); break; case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: b.append("\"").append(rs.getString(index)).append("\""); break; case Types.DATE: case Types.TIMESTAMP: b.append("{ts '"); b.append(rs.getString(index)); b.append("'}"); break; }//from w w w . java 2 s .c o m b.append(AND); } } b.replace(b.length() - AND.length(), b.length(), ""); return b.toString(); }
From source file:com.oracle.tutorial.jdbc.StoredProcedureJavaDBSample.java
public void runStoredProcedures(String coffeeNameArg, double maximumPercentageArg, double newPriceArg) throws SQLException { CallableStatement cs = null;//ww w . j a v a 2 s . c o m try { System.out.println("\nCalling the stored procedure GET_SUPPLIER_OF_COFFEE"); cs = this.con.prepareCall("{call GET_SUPPLIER_OF_COFFEE(?, ?)}"); cs.setString(1, coffeeNameArg); cs.registerOutParameter(2, Types.VARCHAR); cs.execute(); String supplierName = cs.getString(2); if (supplierName != null) { System.out.println("\nSupplier of the coffee " + coffeeNameArg + ": " + supplierName); } else { System.out.println("\nUnable to find the coffee " + coffeeNameArg); } System.out.println("\nCalling the procedure SHOW_SUPPLIERS"); cs = this.con.prepareCall("{call SHOW_SUPPLIERS()}"); ResultSet rs = cs.executeQuery(); while (rs.next()) { String supplier = rs.getString("SUP_NAME"); String coffee = rs.getString("COF_NAME"); System.out.println(supplier + ": " + coffee); } System.out.println("\nContents of COFFEES table before calling RAISE_PRICE:"); CoffeesTable.viewTable(this.con); System.out.println("\nCalling the procedure RAISE_PRICE"); cs = this.con.prepareCall("{call RAISE_PRICE(?,?,?)}"); cs.setString(1, coffeeNameArg); cs.setDouble(2, maximumPercentageArg); cs.registerOutParameter(3, Types.DOUBLE); cs.setDouble(3, newPriceArg); cs.execute(); System.out.println("\nValue of newPrice after calling RAISE_PRICE: " + cs.getFloat(3)); System.out.println("\nContents of COFFEES table after calling RAISE_PRICE:"); CoffeesTable.viewTable(this.con); } catch (SQLException e) { JDBCTutorialUtilities.printSQLException(e); } finally { if (cs != null) { cs.close(); } } }
From source file:com.squid.core.domain.operators.ExtendedType.java
private String getTypeName(int SQLType) { switch (SQLType) { case Types.ARRAY: return "ARRAY"; case Types.BIGINT: return "INTEGER"; 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.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.NCHAR: return "NCHAR"; case Types.NCLOB: return "NCLOB"; case Types.NULL: return "UNDEFINED";// case Types.NUMERIC: return "NUMERIC"; case Types.NVARCHAR: return "NVARCHAR"; case Types.OTHER: return "UNDEFINED";// 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://w ww. j a v a2s .c o m return "UNDEFINED";// } }
From source file:org.nuxeo.ecm.core.storage.sql.jdbc.dialect.DialectSQLServer.java
@Override public void setToPreparedStatement(PreparedStatement ps, int index, Serializable value, Column column) throws SQLException { switch (column.getJdbcType()) { case Types.VARCHAR: case Types.CLOB: setToPreparedStatementString(ps, index, value, column); return;/*from w ww . j av a 2 s. c o m*/ case Types.BIT: ps.setBoolean(index, ((Boolean) value).booleanValue()); return; case Types.TINYINT: case Types.INTEGER: case Types.BIGINT: ps.setLong(index, ((Number) value).longValue()); return; case Types.DOUBLE: ps.setDouble(index, ((Double) value).doubleValue()); return; case Types.TIMESTAMP: setToPreparedStatementTimestamp(ps, index, value, column); return; default: throw new SQLException("Unhandled JDBC type: " + column.getJdbcType()); } }
From source file:org.wso2.cep.broker.RDBMSBrokerType.java
private TableInfo initializeTableInfo(String databaseName, String tableName, Object message, BrokerConfiguration brokerConfiguration, Connection connection) throws SQLException { TableInfo tableInfo = new TableInfo(); tableInfo.setTableName(tableName);/*from www . j a v a2s . c o m*/ // create the table. StringBuilder stringBuilder = new StringBuilder("CREATE TABLE IF NOT EXISTS "); stringBuilder.append(tableName); stringBuilder.append(" ("); boolean appendComma = false; for (Map.Entry<String, Object> entry : (((Map<String, Object>) message).entrySet())) { if (appendComma) { stringBuilder.append(","); } else { appendComma = true; } stringBuilder.append(entry.getKey()).append(" "); if (entry.getValue() instanceof Integer) { stringBuilder.append("INT"); } else if (entry.getValue() instanceof Long) { stringBuilder.append("BIGINT"); } else if (entry.getValue() instanceof Float) { stringBuilder.append("FLOAT"); } else if (entry.getValue() instanceof Double) { stringBuilder.append("DOUBLE"); } else if (entry.getValue() instanceof String) { stringBuilder.append("VARCHAR(255)"); } else if (entry.getValue() instanceof Boolean) { stringBuilder.append("BOOL"); } } stringBuilder.append(")"); Statement statement = connection.createStatement(); statement.executeUpdate(stringBuilder.toString()); statement.close(); ArrayList<Attribute> tableColumnList = new ArrayList<Attribute>(); stringBuilder = new StringBuilder("INSERT INTO "); stringBuilder.append(tableName); stringBuilder.append(" ( "); StringBuilder values = new StringBuilder(""); appendComma = false; DatabaseMetaData databaseMetaData = connection.getMetaData(); ResultSet rs = databaseMetaData.getColumns(null, null, databaseName + "." + tableName, null); while (rs.next()) { AttributeType type = null; int colType = rs.getInt("DATA_TYPE"); switch (colType) { case Types.VARCHAR: type = AttributeType.STRING; break; case Types.INTEGER: type = AttributeType.INT; break; case Types.BIGINT: type = AttributeType.LONG; break; case Types.DOUBLE: type = AttributeType.DOUBLE; break; case Types.FLOAT: type = AttributeType.FLOAT; break; case Types.BOOLEAN: type = AttributeType.BOOL; break; } Attribute attribute = new Attribute(rs.getString("COLUMN_NAME"), type); tableColumnList.add(attribute); if (appendComma) { stringBuilder.append(","); values.append(","); } else { appendComma = true; } stringBuilder.append(attribute.getName()); values.append("?"); } stringBuilder.append(") VALUES ("); stringBuilder.append(values); stringBuilder.append(")"); tableInfo.setColumnOrder(tableColumnList); tableInfo.setPreparedStatement(connection.prepareStatement(stringBuilder.toString())); return tableInfo; }
From source file:org.easyrec.utils.spring.store.dao.DaoUtils.java
public static void setDouble(PreparedStatement stmt, Double value, int index) throws SQLException { if (value == null) { stmt.setNull(index, Types.DOUBLE); return;//from w w w . j a v a 2 s .co m } stmt.setDouble(index, value); }
From source file:org.cloudfoundry.workers.stocks.batch.BatchConfiguration.java
/*** * The Spring Batch {@link org.springframework.batch.item.ItemWriter item * writer} persists the {@link StockSymbolLookup} lookup results into a * table (<CODE>STOCKS_DATA</CODE>). * /*from ww w .ja v a2 s .c o m*/ * @param dateOfAnalysis */ @Bean(name = "writer") @Scope("step") public JdbcBatchItemWriter<StockSymbolLookup> writer( final @Value("#{jobParameters['date']}") Date dateOfAnalysis) { JdbcBatchItemWriter<StockSymbolLookup> jdbcBatchItemWriter = new JdbcBatchItemWriter<StockSymbolLookup>(); jdbcBatchItemWriter.setSql( "INSERT INTO STOCKS_DATA( DATE_ANALYSED, HIGH_PRICE, LOW_PRICE, CLOSING_PRICE, SYMBOL) VALUES ( :da, :hp, :lp, :cp, :s ) "); jdbcBatchItemWriter.setDataSource(dsConfig.dataSource()); jdbcBatchItemWriter .setItemSqlParameterSourceProvider(new ItemSqlParameterSourceProvider<StockSymbolLookup>() { @Override public SqlParameterSource createSqlParameterSource(StockSymbolLookup item) { return new MapSqlParameterSource() .addValue("da", new java.sql.Date(dateOfAnalysis.getTime()), Types.DATE) .addValue("hp", item.getHighPrice(), Types.DOUBLE) .addValue("lp", item.getLowPrice(), Types.DOUBLE).addValue("s", item.getTicker()) .addValue("si", item.getId(), Types.BIGINT) .addValue("cp", item.getLastValueWhileOpen(), Types.DOUBLE); } }); return jdbcBatchItemWriter; }
From source file:fll.web.api.SubjectiveScoresServlet.java
@SuppressFBWarnings(value = { "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING" }, justification = "columns and category are dynamic") @Override// w w w .j a v a2 s .c o m protected final void doPost(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { int numModified = 0; final ObjectMapper jsonMapper = new ObjectMapper(); final ServletContext application = getServletContext(); final ChallengeDescription challengeDescription = ApplicationAttributes .getChallengeDescription(application); Connection connection = null; PreparedStatement deletePrep = null; PreparedStatement noShowPrep = null; PreparedStatement insertPrep = null; try { final DataSource datasource = ApplicationAttributes.getDataSource(application); connection = datasource.getConnection(); final int currentTournament = Queries.getCurrentTournament(connection); final StringWriter debugWriter = new StringWriter(); IOUtils.copy(request.getReader(), debugWriter); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Read data: " + debugWriter.toString()); } final Reader reader = new StringReader(debugWriter.toString()); final Map<String, Map<String, Map<Integer, SubjectiveScore>>> allScores = jsonMapper.readValue(reader, ScoresTypeInfo.INSTANCE); for (final Map.Entry<String, Map<String, Map<Integer, SubjectiveScore>>> catEntry : allScores .entrySet()) { final String category = catEntry.getKey(); final ScoreCategory categoryDescription = challengeDescription .getSubjectiveCategoryByName(category); deletePrep = connection.prepareStatement("DELETE FROM " + category // + " WHERE TeamNumber = ?" // + " AND Tournament = ?" // + " AND Judge = ?" // ); deletePrep.setInt(2, currentTournament); noShowPrep = connection.prepareStatement("INSERT INTO " + category // + "(TeamNumber, Tournament, Judge, NoShow) VALUES(?, ?, ?, ?)"); noShowPrep.setInt(2, currentTournament); noShowPrep.setBoolean(4, true); final int NUM_COLUMNS_BEFORE_GOALS = 6; insertPrep = createInsertStatement(connection, categoryDescription); insertPrep.setInt(2, currentTournament); insertPrep.setBoolean(4, false); for (final Map.Entry<String, Map<Integer, SubjectiveScore>> judgeEntry : catEntry.getValue() .entrySet()) { final String judgeId = judgeEntry.getKey(); deletePrep.setString(3, judgeId); noShowPrep.setString(3, judgeId); insertPrep.setString(3, judgeId); for (final Map.Entry<Integer, SubjectiveScore> teamEntry : judgeEntry.getValue().entrySet()) { final int teamNumber = teamEntry.getKey(); final SubjectiveScore score = teamEntry.getValue(); if (score.getModified()) { deletePrep.setInt(1, teamNumber); noShowPrep.setInt(1, teamNumber); insertPrep.setInt(1, teamNumber); insertPrep.setString(5, score.getNote()); ++numModified; if (score.getDeleted()) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Deleting team: " + teamNumber + " judge: " + judgeId + " category: " + category); } deletePrep.executeUpdate(); } else if (score.getNoShow()) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("NoShow team: " + teamNumber + " judge: " + judgeId + " category: " + category); } deletePrep.executeUpdate(); noShowPrep.executeUpdate(); } else { if (LOGGER.isTraceEnabled()) { LOGGER.trace("scores for team: " + teamNumber + " judge: " + judgeId + " category: " + category); } int goalIndex = 0; for (final AbstractGoal goalDescription : categoryDescription.getGoals()) { if (!goalDescription.isComputed()) { final String goalName = goalDescription.getName(); if (goalDescription.isEnumerated()) { final String value = score.getEnumSubScores().get(goalName); if (null == value) { insertPrep.setNull(goalIndex + NUM_COLUMNS_BEFORE_GOALS, Types.VARCHAR); } else { insertPrep.setString(goalIndex + NUM_COLUMNS_BEFORE_GOALS, value.trim()); } } else { final Double value = score.getStandardSubScores().get(goalName); if (null == value) { insertPrep.setNull(goalIndex + NUM_COLUMNS_BEFORE_GOALS, Types.DOUBLE); } else { insertPrep.setDouble(goalIndex + NUM_COLUMNS_BEFORE_GOALS, value); } } ++goalIndex; } // not computed } // end for deletePrep.executeUpdate(); insertPrep.executeUpdate(); } } // is modified } // foreach team score } // foreach judge SQLFunctions.close(deletePrep); deletePrep = null; SQLFunctions.close(noShowPrep); noShowPrep = null; SQLFunctions.close(insertPrep); insertPrep = null; } // foreach category UploadSubjectiveData.removeNullSubjectiveRows(connection, currentTournament, challengeDescription); final Tournament tournament = Tournament.findTournamentByID(connection, currentTournament); tournament.recordSubjectiveModified(connection); final UploadResult result = new UploadResult(true, "Successfully uploaded scores", numModified); response.reset(); response.setContentType("application/json"); final PrintWriter writer = response.getWriter(); jsonMapper.writeValue(writer, result); } catch (final SQLException sqle) { LOGGER.error("Error uploading scores", sqle); final UploadResult result = new UploadResult(false, sqle.getMessage(), numModified); response.reset(); response.setContentType("application/json"); final PrintWriter writer = response.getWriter(); jsonMapper.writeValue(writer, result); } finally { SQLFunctions.close(deletePrep); SQLFunctions.close(noShowPrep); SQLFunctions.close(insertPrep); SQLFunctions.close(connection); } }