List of usage examples for java.sql Types BIGINT
int BIGINT
To view the source code for java.sql Types BIGINT.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BIGINT
.
From source file:org.sakaiproject.tool.tasklist.impl.TaskListManagerJdbcImpl.java
public boolean saveTask(Task t) { try {//from w ww .j av a 2s. co m if (t.getId() == null) { // if the id is not set the we are inserting a new record getJdbcTemplate().update(TASK_INSERT_QUERY, new Object[] { t.getOwner(), t.getSiteId(), t.getCreationDate(), t.getTask() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.CLOB }); } else { getJdbcTemplate().update(TASK_UPDATE_QUERY, new Object[] { t.getOwner(), t.getSiteId(), t.getTask(), t.getId() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.CLOB, Types.BIGINT }); } } catch (DataAccessException e) { log.error("Exception: Could not add task:" + e.toString()); e.printStackTrace(); return false; } return true; }
From source file:com.sangupta.fileanalysis.db.DBResultViewer.java
private int getColumnSize(final String tableName, final String columnName, final int columnType) { // check if we have the value in database cache int size = database.getColSize(tableName, columnName); if (size > 0) { return size; }/*from w ww . j av a 2s.co m*/ switch (columnType) { case Types.VARCHAR: return 255; case Types.INTEGER: return 10; case Types.BOOLEAN: return 3; case Types.DOUBLE: return 14; case Types.BIGINT: return 20; case Types.TIMESTAMP: return 26; } return 10; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSybase.CFAsteriskSybaseTenantTable.java
public long nextTSecGroupMemberIdGen(CFSecurityAuthorization Authorization, CFSecurityTenantPKey PKey) { final String S_ProcName = "nextTSecGroupMemberIdGen"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); }/* w w w .ja v a 2 s . co m*/ Connection cnx = schema.getCnx(); long Id = PKey.getRequiredId(); CallableStatement stmtSelectNextTSecGroupMemberIdGen = null; try { String sql = "{ call sp_next_tsecgroupmemberidgen( ?" + ", " + "?" + " ) }"; stmtSelectNextTSecGroupMemberIdGen = cnx.prepareCall(sql); int argIdx = 1; stmtSelectNextTSecGroupMemberIdGen.registerOutParameter(argIdx++, java.sql.Types.BIGINT); stmtSelectNextTSecGroupMemberIdGen.setLong(argIdx++, Id); stmtSelectNextTSecGroupMemberIdGen.execute(); long nextId = stmtSelectNextTSecGroupMemberIdGen.getLong(1); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (stmtSelectNextTSecGroupMemberIdGen != null) { try { stmtSelectNextTSecGroupMemberIdGen.close(); } catch (SQLException e) { } stmtSelectNextTSecGroupMemberIdGen = null; } } }
From source file:net.solarnetwork.node.dao.jdbc.consumption.JdbcConsumptionDatumDao.java
@Override protected void setStoreStatementValues(ConsumptionDatum datum, PreparedStatement ps) throws SQLException { int col = 1;/*w ww.j a v a 2 s .c o m*/ ps.setTimestamp(col++, new java.sql.Timestamp( datum.getCreated() == null ? System.currentTimeMillis() : datum.getCreated().getTime())); ps.setString(col++, datum.getSourceId() == null ? "" : datum.getSourceId()); if (datum.getLocationId() == null) { ps.setNull(col++, Types.BIGINT); } else { ps.setLong(col++, datum.getLocationId()); } if (datum.getWatts() == null) { ps.setNull(col++, Types.INTEGER); } else { ps.setInt(col++, datum.getWatts()); } if (datum.getWattHourReading() == null) { ps.setNull(col++, Types.BIGINT); } else { ps.setLong(col++, datum.getWattHourReading()); } }
From source file:org.syncope.core.util.ImportExport.java
private void setParameters(final String tableName, final Attributes atts, final Query query) { Map<String, Integer> colTypes = new HashMap<String, Integer>(); Connection conn = DataSourceUtils.getConnection(dataSource); ResultSet rs = null;//from w w w . j av a 2 s .com Statement stmt = null; try { stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT * FROM " + tableName); for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) { colTypes.put(rs.getMetaData().getColumnName(i + 1).toUpperCase(), rs.getMetaData().getColumnType(i + 1)); } } catch (SQLException e) { LOG.error("While", e); } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException e) { LOG.error("While closing statement", e); } } if (rs != null) { try { rs.close(); } catch (SQLException e) { LOG.error("While closing result set", e); } } DataSourceUtils.releaseConnection(conn, dataSource); } for (int i = 0; i < atts.getLength(); i++) { Integer colType = colTypes.get(atts.getQName(i).toUpperCase()); if (colType == null) { LOG.warn("No column type found for {}", atts.getQName(i).toUpperCase()); colType = Types.VARCHAR; } switch (colType) { case Types.NUMERIC: case Types.REAL: case Types.INTEGER: case Types.TINYINT: try { query.setParameter(i + 1, Integer.valueOf(atts.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Integer '{}'", atts.getValue(i)); query.setParameter(i + 1, atts.getValue(i)); } break; case Types.DECIMAL: case Types.BIGINT: try { query.setParameter(i + 1, Long.valueOf(atts.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Long '{}'", atts.getValue(i)); query.setParameter(i + 1, atts.getValue(i)); } break; case Types.DOUBLE: try { query.setParameter(i + 1, Double.valueOf(atts.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Double '{}'", atts.getValue(i)); query.setParameter(i + 1, atts.getValue(i)); } break; case Types.FLOAT: try { query.setParameter(i + 1, Float.valueOf(atts.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Float '{}'", atts.getValue(i)); query.setParameter(i + 1, atts.getValue(i)); } break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: try { query.setParameter(i + 1, DateUtils.parseDate(atts.getValue(i), SyncopeConstants.DATE_PATTERNS), TemporalType.TIMESTAMP); } catch (ParseException e) { LOG.error("Unparsable Date '{}'", atts.getValue(i)); query.setParameter(i + 1, atts.getValue(i)); } break; case Types.BIT: case Types.BOOLEAN: query.setParameter(i + 1, "1".equals(atts.getValue(i)) ? Boolean.TRUE : Boolean.FALSE); break; default: query.setParameter(i + 1, atts.getValue(i)); } } }
From source file:net.solarnetwork.node.dao.jdbc.power.JdbcPowerDatumDao.java
@Override protected void setStoreStatementValues(PowerDatum datum, PreparedStatement ps) throws SQLException { int col = 1;//w w w .j a va2 s . co m ps.setTimestamp(col++, new java.sql.Timestamp( datum.getCreated() == null ? System.currentTimeMillis() : datum.getCreated().getTime())); ps.setString(col++, datum.getSourceId() == null ? "" : datum.getSourceId()); if (datum.getLocationId() == null) { ps.setNull(col++, Types.BIGINT); } else { ps.setLong(col++, datum.getLocationId()); } if (datum.getWatts() == null) { ps.setNull(col++, Types.INTEGER); } else { ps.setInt(col++, datum.getWatts()); } if (datum.getBatteryVolts() == null) { ps.setNull(col++, Types.FLOAT); } else { ps.setFloat(col++, datum.getBatteryVolts()); } if (datum.getBatteryAmpHours() == null) { ps.setNull(col++, Types.DOUBLE); } else { ps.setDouble(col++, datum.getBatteryAmpHours()); } if (datum.getDcOutputVolts() == null) { ps.setNull(col++, Types.FLOAT); } else { ps.setFloat(col++, datum.getDcOutputVolts()); } if (datum.getDcOutputAmps() == null) { ps.setNull(col++, Types.FLOAT); } else { ps.setFloat(col++, datum.getDcOutputAmps()); } if (datum.getAcOutputVolts() == null) { ps.setNull(col++, Types.FLOAT); } else { ps.setFloat(col++, datum.getAcOutputVolts()); } if (datum.getAcOutputAmps() == null) { ps.setNull(col++, Types.FLOAT); } else { ps.setFloat(col++, datum.getAcOutputAmps()); } if (datum.getWattHourReading() == null) { ps.setNull(col++, Types.BIGINT); } else { ps.setLong(col++, datum.getWattHourReading()); } if (datum.getAmpHourReading() == null) { ps.setNull(col++, Types.DOUBLE); } else { ps.setDouble(col++, datum.getAmpHourReading()); } }
From source file:org.sakaiproject.tool.tasklist.impl.TaskListManagerJdbcImpl.java
public boolean deleteTask(Task t) { try {// ww w . j av a 2s . co m getJdbcTemplate().update(TASK_DELETE_QUERY, new Object[] { t.getId() }, new int[] { Types.BIGINT }); } catch (DataAccessException e) { log.error("Exception: Could not delete task:" + t.getId() + ":" + e.toString()); e.printStackTrace(); return false; } return true; }
From source file:org.apache.syncope.core.util.ImportExport.java
private void setParameters(final String tableName, final Attributes attrs, final Query query) { Map<String, Integer> colTypes = new HashMap<String, Integer>(); final Table table = getTable(tableName); for (int i = 0; i < attrs.getLength(); i++) { Integer colType = table.getColumn(QualifiedDBIdentifier.newColumn(attrs.getQName(i))).getType(); if (colType == null) { LOG.warn("No column type found for {}", attrs.getQName(i).toUpperCase()); colType = Types.VARCHAR; }//ww w.ja va 2s . c o m switch (colType) { case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: try { query.setParameter(i + 1, Integer.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Integer '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.NUMERIC: case Types.DECIMAL: case Types.BIGINT: try { query.setParameter(i + 1, Long.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Long '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.DOUBLE: try { query.setParameter(i + 1, Double.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Double '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.REAL: case Types.FLOAT: try { query.setParameter(i + 1, Float.valueOf(attrs.getValue(i))); } catch (NumberFormatException e) { LOG.error("Unparsable Float '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: try { query.setParameter(i + 1, DateUtils.parseDate(attrs.getValue(i), SyncopeConstants.DATE_PATTERNS), TemporalType.TIMESTAMP); } catch (ParseException e) { LOG.error("Unparsable Date '{}'", attrs.getValue(i)); query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.BIT: case Types.BOOLEAN: query.setParameter(i + 1, "1".equals(attrs.getValue(i)) ? Boolean.TRUE : Boolean.FALSE); break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: try { query.setParameter(i + 1, Hex.decode(attrs.getValue(i))); } catch (IllegalArgumentException e) { query.setParameter(i + 1, attrs.getValue(i)); } break; case Types.BLOB: try { query.setParameter(i + 1, Hex.decode(attrs.getValue(i))); } catch (IllegalArgumentException e) { LOG.warn("Error decoding hex string to specify a blob parameter", e); query.setParameter(i + 1, attrs.getValue(i)); } catch (Exception e) { LOG.warn("Error creating a new blob parameter", e); } break; default: query.setParameter(i + 1, attrs.getValue(i)); } } }
From source file:it.greenvulcano.gvesb.datahandling.dbo.utils.StandardRowSetBuilder.java
public int build(Document doc, String id, ResultSet rs, Set<Integer> keyField, Map<String, FieldFormatter> fieldNameToFormatter, Map<String, FieldFormatter> fieldIdToFormatter) throws Exception { if (rs == null) { return 0; }// ww w . j a v a2 s .c o m int rowCounter = 0; Element docRoot = doc.getDocumentElement(); ResultSetMetaData metadata = rs.getMetaData(); FieldFormatter[] fFormatters = buildFormatterArray(metadata, fieldNameToFormatter, fieldIdToFormatter); boolean noKey = ((keyField == null) || keyField.isEmpty()); //boolean isNull = false; Element data = null; Element row = null; Element col = null; Text text = null; String textVal = null; String precKey = null; String colKey = null; Map<String, String> keyAttr = new HashMap<String, String>(); while (rs.next()) { if (rowCounter % 10 == 0) { ThreadUtils.checkInterrupted(getClass().getSimpleName(), name, logger); } row = parser.createElement(doc, AbstractDBO.ROW_NAME); parser.setAttribute(row, AbstractDBO.ID_NAME, id); for (int j = 1; j <= metadata.getColumnCount(); j++) { FieldFormatter fF = fFormatters[j]; //isNull = false; col = parser.createElement(doc, AbstractDBO.COL_NAME); switch (metadata.getColumnType(j)) { case Types.DATE: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DATE_TYPE); java.sql.Date dateVal = rs.getDate(j); textVal = processDateTime(col, fF, dateVal, AbstractDBO.DEFAULT_DATE_FORMAT); } break; case Types.TIME: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.TIME_TYPE); java.sql.Time dateVal = rs.getTime(j); textVal = processDateTime(col, fF, dateVal, AbstractDBO.DEFAULT_TIME_FORMAT); } break; case Types.TIMESTAMP: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.TIMESTAMP_TYPE); Timestamp dateVal = rs.getTimestamp(j); textVal = processDateTime(col, fF, dateVal, AbstractDBO.DEFAULT_DATE_FORMAT); } break; case Types.DOUBLE: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); double numVal = rs.getDouble(j); textVal = processDouble(col, fF, numVal); } break; case Types.FLOAT: case Types.REAL: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.FLOAT_TYPE); float numVal = rs.getFloat(j); textVal = processDouble(col, fF, numVal); } break; case Types.BIGINT: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.BIGINT_TYPE); long numVal = rs.getLong(j); parser.setAttribute(col, AbstractDBO.NULL_NAME, "false"); textVal = String.valueOf(numVal); } break; case Types.INTEGER: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.INTEGER_TYPE); int numVal = rs.getInt(j); parser.setAttribute(col, AbstractDBO.NULL_NAME, "false"); textVal = String.valueOf(numVal); } break; case Types.SMALLINT: case Types.TINYINT: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.SMALLINT_TYPE); short numVal = rs.getShort(j); parser.setAttribute(col, AbstractDBO.NULL_NAME, "false"); textVal = String.valueOf(numVal); } break; case Types.NUMERIC: case Types.DECIMAL: { BigDecimal bigdecimal = rs.getBigDecimal(j); boolean isNull = bigdecimal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { if (metadata.getScale(j) > 0) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DECIMAL_TYPE); } else { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NUMERIC_TYPE); } textVal = ""; } else { if (fF != null) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DECIMAL_TYPE); parser.setAttribute(col, AbstractDBO.FORMAT_NAME, fF.getNumberFormat()); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, fF.getGroupSeparator()); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, fF.getDecSeparator()); textVal = fF.formatNumber(bigdecimal); } else if (metadata.getScale(j) > 0) { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DECIMAL_TYPE); parser.setAttribute(col, AbstractDBO.FORMAT_NAME, numberFormat); parser.setAttribute(col, AbstractDBO.GRP_SEPARATOR_NAME, groupSeparator); parser.setAttribute(col, AbstractDBO.DEC_SEPARATOR_NAME, decSeparator); textVal = numberFormatter.format(bigdecimal); } else { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NUMERIC_TYPE); textVal = bigdecimal.toString(); } } } break; case Types.BOOLEAN: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.BOOLEAN_TYPE); boolean bVal = rs.getBoolean(j); parser.setAttribute(col, AbstractDBO.NULL_NAME, "false"); textVal = String.valueOf(bVal); } break; case Types.SQLXML: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.XML_TYPE); SQLXML xml = rs.getSQLXML(j); boolean isNull = xml == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } else { textVal = xml.getString(); } } break; case Types.NCHAR: case Types.NVARCHAR: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.NSTRING_TYPE); textVal = rs.getNString(j); if (textVal == null) { textVal = ""; } } break; case Types.CHAR: case Types.VARCHAR: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.STRING_TYPE); textVal = rs.getString(j); boolean isNull = textVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } } break; case Types.NCLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.LONG_NSTRING_TYPE); NClob clob = rs.getNClob(j); if (clob != null) { Reader is = clob.getCharacterStream(); StringWriter str = new StringWriter(); IOUtils.copy(is, str); is.close(); textVal = str.toString(); } else { textVal = ""; } } break; case Types.CLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.LONG_STRING_TYPE); Clob clob = rs.getClob(j); if (clob != null) { Reader is = clob.getCharacterStream(); StringWriter str = new StringWriter(); IOUtils.copy(is, str); is.close(); textVal = str.toString(); } else { textVal = ""; } } break; case Types.BLOB: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.BASE64_TYPE); Blob blob = rs.getBlob(j); boolean isNull = blob == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } else { InputStream is = blob.getBinaryStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(is, baos); is.close(); try { byte[] buffer = Arrays.copyOf(baos.toByteArray(), (int) blob.length()); textVal = Base64.getEncoder().encodeToString(buffer); } catch (SQLFeatureNotSupportedException exc) { textVal = Base64.getEncoder().encodeToString(baos.toByteArray()); } } } break; default: { parser.setAttribute(col, AbstractDBO.TYPE_NAME, AbstractDBO.DEFAULT_TYPE); textVal = rs.getString(j); boolean isNull = textVal == null; parser.setAttribute(col, AbstractDBO.NULL_NAME, String.valueOf(isNull)); if (isNull) { textVal = ""; } } } if (textVal != null) { text = doc.createTextNode(textVal); col.appendChild(text); } if (!noKey && keyField.contains(new Integer(j))) { if (textVal != null) { if (colKey == null) { colKey = textVal; } else { colKey += "##" + textVal; } keyAttr.put("key_" + j, textVal); } } else { row.appendChild(col); } } if (noKey) { if (data == null) { data = parser.createElement(doc, AbstractDBO.DATA_NAME); parser.setAttribute(data, AbstractDBO.ID_NAME, id); } } else if ((colKey != null) && !colKey.equals(precKey)) { if (data != null) { docRoot.appendChild(data); } data = parser.createElement(doc, AbstractDBO.DATA_NAME); parser.setAttribute(data, AbstractDBO.ID_NAME, id); for (Entry<String, String> keyAttrEntry : keyAttr.entrySet()) { parser.setAttribute(data, keyAttrEntry.getKey(), keyAttrEntry.getValue()); } keyAttr.clear(); precKey = colKey; } colKey = null; data.appendChild(row); rowCounter++; } if (data != null) { docRoot.appendChild(data); } return rowCounter; }
From source file:org.apache.camel.processor.aggregate.jdbc.OptimisticLockingJdbcAggregationRepository.java
@Override public Exchange add(CamelContext camelContext, String key, Exchange exchange) { return getTransactionTemplate().execute(new TransactionCallback<Exchange>() { @Override//from ww w . jav a2 s . com public Exchange doInTransaction(TransactionStatus status) { Exchange result = get(camelContext, key); try { log.debug(String.format("Adding exchange with key: [%s]", key)); byte[] marshalledExchange = getCodec().marshallExchange(camelContext, exchange, true); boolean present = getJdbcTemplate().queryForObject( String.format("SELECT COUNT(*) FROM %1$s WHERE %2$s=?", getRepositoryName(), ID_KEY), new Object[] { key }, new int[] { Types.VARCHAR }, Integer.class) != 0; if (present) { long version = exchange.getProperty(VERSION_EXCHANGE_PROPERTY, Long.class); log.debug(String.format("Updating record with key: [%s] and version: [%s].", key, version)); int affectedRows = getJdbcTemplate().update( String.format("UPDATE %1$s SET %2$s=?, %3$s=? WHERE %4$s=? AND %3$s=?", getRepositoryName(), EXCHANGE_KEY, VERSION_KEY, ID_KEY), new Object[] { new SqlLobValue(marshalledExchange, getLobHandler()), version + 1, key, version }, new int[] { Types.BLOB, Types.BIGINT, Types.VARCHAR, Types.BIGINT }); if (affectedRows < 1) { throw new RuntimeException(String.format( "Error updating record with key: [%s] and version: [%s]. Stale version...", key, version)); } } else { log.debug(String.format("Inserting record with key: [%s].", key)); getJdbcTemplate().update( String.format("INSERT INTO %1$s (%2$s, %3$s, %4$s) VALUES (?, ?, ?)", getRepositoryName(), ID_KEY, EXCHANGE_KEY, VERSION_KEY), new Object[] { key, new SqlLobValue(marshalledExchange, getLobHandler()), 1L }, new int[] { Types.VARCHAR, Types.BLOB, Types.BIGINT }); } } catch (Exception e) { throw new RuntimeException(String.format("Error adding to repository [%s] with key [%s].", getRepositoryName(), key), e); } return result; } }); }