List of usage examples for java.sql Types INTEGER
int INTEGER
To view the source code for java.sql Types INTEGER.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type INTEGER
.
From source file:org.owasp.proxy.http.dao.JdbcMessageDAO.java
public int getMessageContentId(int headerId) throws DataAccessException { try {/*from w w w. ja v a 2s. co m*/ MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(ID, headerId, Types.INTEGER); SimpleJdbcTemplate template = new SimpleJdbcTemplate(getNamedParameterJdbcTemplate()); return template.queryForInt(SELECT_CONTENT_ID, params); } catch (EmptyResultDataAccessException erdae) { return -1; } }
From source file:com.funambol.foundation.items.dao.PIMNoteDAO.java
public void addItem(NoteWrapper nw) throws DAOException { if (log.isTraceEnabled()) { log.trace("PIMNoteDAO addItem begin"); }/*from ww w. ja v a2 s. com*/ Connection con = null; PreparedStatement ps = null; long id = 0; String sId = null; Timestamp lastUpdate = nw.getLastUpdate(); if (lastUpdate == null) { lastUpdate = new Timestamp(System.currentTimeMillis()); } try { // Looks up the data source when the first connection is created con = getUserDataSource().getRoutedConnection(userId); // calculate table row id sId = nw.getId(); if (sId == null) { // ...as it should be sId = getNextID(); nw.setId(sId); } id = Long.parseLong(sId); ps = con.prepareStatement(SQL_INSERT_INTO_FNBL_PIM_NOTE); int k = 1; // // GENERAL // if (log.isTraceEnabled()) { log.trace("Preparing statement with ID " + id); } ps.setLong(k++, id); if (log.isTraceEnabled()) { log.trace("Preparing statement with user ID " + userId); } ps.setString(k++, userId); ps.setLong(k++, lastUpdate.getTime()); ps.setString(k++, String.valueOf(Def.PIM_STATE_NEW)); Note note = nw.getNote(); ps.setString(k++, StringUtils.left(note.getSubject().getPropertyValueAsString(), SQL_SUBJECT_DIM)); String textDescription = note.getTextDescription().getPropertyValueAsString(); if (textDescription != null) { textDescription = textDescription.replace('\0', ' '); } String truncatedTextDescription = StringUtils.left(textDescription, SQL_TEXTDESCRIPTION_DIM); ps.setString(k++, truncatedTextDescription); ps.setString(k++, truncateCategoriesField(note.getCategories().getPropertyValueAsString(), SQL_CATEGORIES_DIM)); ps.setString(k++, truncateFolderField(note.getFolder().getPropertyValueAsString(), SQL_FOLDER_DIM)); Property color = note.getColor(); Property height = note.getHeight(); Property width = note.getWidth(); Property top = note.getTop(); Property left = note.getLeft(); if (Property.isEmptyProperty(color)) { ps.setNull(k++, Types.INTEGER); } else { ps.setInt(k++, Integer.parseInt(color.getPropertyValueAsString())); } if (Property.isEmptyProperty(height)) { ps.setNull(k++, Types.INTEGER); } else { ps.setInt(k++, Integer.parseInt(height.getPropertyValueAsString())); } if (Property.isEmptyProperty(width)) { ps.setNull(k++, Types.INTEGER); } else { ps.setInt(k++, Integer.parseInt(width.getPropertyValueAsString())); } if (Property.isEmptyProperty(top)) { ps.setNull(k++, Types.INTEGER); } else { ps.setInt(k++, Integer.parseInt(top.getPropertyValueAsString())); } if (Property.isEmptyProperty(left)) { ps.setNull(k++, Types.INTEGER); } else { ps.setInt(k++, Integer.parseInt(left.getPropertyValueAsString())); } Long crc = calculateCrc(truncatedTextDescription); if (crc == null) { ps.setNull(k++, Types.BIGINT); } else { ps.setLong(k++, crc); } ps.executeUpdate(); } catch (Exception e) { throw new DAOException("Error adding note.", e); } finally { DBTools.close(con, ps, null); } if (log.isTraceEnabled()) { log.trace("Added item with ID " + id); log.trace("PIMNoteDAO addItem end"); } }
From source file:org.jamwiki.db.CacheQueryHandler.java
/** * *//*from www .ja va 2 s . c om*/ @Override public void insertTopicVersions(List<TopicVersion> topicVersions) { Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; boolean useBatch = (topicVersions.size() > 1); try { conn = DatabaseConnection.getConnection(); if (!this.autoIncrementPrimaryKeys()) { stmt = conn.prepareStatement(STATEMENT_INSERT_TOPIC_VERSION); } else if (useBatch) { // generated keys don't work in batch mode stmt = conn.prepareStatement(STATEMENT_INSERT_TOPIC_VERSION_AUTO_INCREMENT); } else { stmt = conn.prepareStatement(STATEMENT_INSERT_TOPIC_VERSION_AUTO_INCREMENT, Statement.RETURN_GENERATED_KEYS); } int topicVersionId = -1; if (!this.autoIncrementPrimaryKeys() || useBatch) { // manually retrieve next topic version id when using batch // mode or when the database doesn't support generated keys. topicVersionId = DatabaseConnection.executeSequenceQuery(STATEMENT_SELECT_TOPIC_VERSION_SEQUENCE); } for (TopicVersion topicVersion : topicVersions) { if (!this.autoIncrementPrimaryKeys() || useBatch) { // FIXME - if two threads update the database simultaneously then // it is possible that this code could set the topic version ID // to a value that is different from what the database ends up // using. topicVersion.setTopicVersionId(topicVersionId++); } StringReader sr = null; try { int index = 1; stmt.setInt(index++, topicVersion.getTopicVersionId()); if (topicVersion.getEditDate() == null) { topicVersion.setEditDate(new Timestamp(System.currentTimeMillis())); } stmt.setInt(index++, topicVersion.getTopicId()); stmt.setString(index++, topicVersion.getEditComment()); //pass the content into a stream to be passed to Cach sr = new StringReader(topicVersion.getVersionContent()); stmt.setCharacterStream(index++, sr, topicVersion.getVersionContent().length()); if (topicVersion.getAuthorId() == null) { stmt.setNull(index++, Types.INTEGER); } else { stmt.setInt(index++, topicVersion.getAuthorId()); } stmt.setInt(index++, topicVersion.getEditType()); stmt.setString(index++, topicVersion.getAuthorDisplay()); stmt.setTimestamp(index++, topicVersion.getEditDate()); if (topicVersion.getPreviousTopicVersionId() == null) { stmt.setNull(index++, Types.INTEGER); } else { stmt.setInt(index++, topicVersion.getPreviousTopicVersionId()); } stmt.setInt(index++, topicVersion.getCharactersChanged()); stmt.setString(index++, topicVersion.getVersionParamString()); } finally { if (sr != null) { sr.close(); } } if (useBatch) { stmt.addBatch(); } else { stmt.executeUpdate(); } if (this.autoIncrementPrimaryKeys() && !useBatch) { rs = stmt.getGeneratedKeys(); if (!rs.next()) { throw new SQLException("Unable to determine auto-generated ID for database record"); } topicVersion.setTopicVersionId(rs.getInt(1)); } } if (useBatch) { stmt.executeBatch(); } } catch (SQLException e) { throw new UncategorizedSQLException("insertTopicVersions", null, e); } finally { DatabaseConnection.closeConnection(conn, stmt, rs); } }
From source file:org.waarp.common.database.data.AbstractDbData.java
/** * Set Value into PreparedStatement/* www .j av a 2s . c o m*/ * * @param ps * @param value * @param rank * >= 1 * @throws WaarpDatabaseSqlException */ static public void setTrueValue(PreparedStatement ps, DbValue value, int rank) throws WaarpDatabaseSqlException { try { switch (value.type) { case Types.VARCHAR: if (value.value == null) { ps.setNull(rank, Types.VARCHAR); break; } ps.setString(rank, (String) value.value); break; case Types.LONGVARCHAR: if (value.value == null) { ps.setNull(rank, Types.LONGVARCHAR); break; } ps.setString(rank, (String) value.value); break; case Types.BIT: if (value.value == null) { ps.setNull(rank, Types.BIT); break; } ps.setBoolean(rank, (Boolean) value.value); break; case Types.TINYINT: if (value.value == null) { ps.setNull(rank, Types.TINYINT); break; } ps.setByte(rank, (Byte) value.value); break; case Types.SMALLINT: if (value.value == null) { ps.setNull(rank, Types.SMALLINT); break; } ps.setShort(rank, (Short) value.value); break; case Types.INTEGER: if (value.value == null) { ps.setNull(rank, Types.INTEGER); break; } ps.setInt(rank, (Integer) value.value); break; case Types.BIGINT: if (value.value == null) { ps.setNull(rank, Types.BIGINT); break; } ps.setLong(rank, (Long) value.value); break; case Types.REAL: if (value.value == null) { ps.setNull(rank, Types.REAL); break; } ps.setFloat(rank, (Float) value.value); break; case Types.DOUBLE: if (value.value == null) { ps.setNull(rank, Types.DOUBLE); break; } ps.setDouble(rank, (Double) value.value); break; case Types.VARBINARY: if (value.value == null) { ps.setNull(rank, Types.VARBINARY); break; } ps.setBytes(rank, (byte[]) value.value); break; case Types.DATE: if (value.value == null) { ps.setNull(rank, Types.DATE); break; } ps.setDate(rank, (Date) value.value); break; case Types.TIMESTAMP: if (value.value == null) { ps.setNull(rank, Types.TIMESTAMP); break; } ps.setTimestamp(rank, (Timestamp) value.value); break; case Types.CLOB: if (value.value == null) { ps.setNull(rank, Types.CLOB); break; } ps.setClob(rank, (Reader) value.value); break; case Types.BLOB: if (value.value == null) { ps.setNull(rank, Types.BLOB); break; } ps.setBlob(rank, (InputStream) value.value); break; default: throw new WaarpDatabaseSqlException("Type not supported: " + value.type + " at " + rank); } } catch (ClassCastException e) { throw new WaarpDatabaseSqlException("Setting values casting error: " + value.type + " at " + rank, e); } catch (SQLException e) { DbSession.error(e); throw new WaarpDatabaseSqlException("Setting values in error: " + value.type + " at " + rank, e); } }
From source file:org.owasp.proxy.http.dao.JdbcMessageDAO.java
public int getMessageContentSize(int id) throws DataAccessException { try {// ww w .jav a2 s. c om MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(ID, id, Types.INTEGER); SimpleJdbcTemplate template = new SimpleJdbcTemplate(getNamedParameterJdbcTemplate()); return template.queryForInt(SELECT_CONTENT_SIZE, params); } catch (EmptyResultDataAccessException erdae) { return -1; } }
From source file:ca.sqlpower.sqlobject.TestSQLTable.java
public void testAddColumn() throws SQLObjectException { SQLTable table1 = db.getTableByName("REGRESSION_TEST1"); assertEquals(2, table1.getColumns().size()); SQLColumn newColumn = new SQLColumn(table1, "my new column", Types.INTEGER, 10, 0); table1.addColumn(newColumn, 2);// w w w . j a v a 2 s . com SQLColumn addedCol = table1.getColumn(2); assertSame("Column at index 2 isn't same object as we added", newColumn, addedCol); }
From source file:com.streamsets.pipeline.stage.it.DriftIT.java
@Test public void testRemovedColumn() throws Exception { HiveMetadataProcessor processor = new HiveMetadataProcessorBuilder().build(); HiveMetastoreTarget hiveTarget = new HiveMetastoreTargetBuilder().build(); List<Record> records = new LinkedList<>(); Map<String, Field> map = new LinkedHashMap<>(); map.put("id", Field.create(Field.Type.INTEGER, 1)); map.put("removed", Field.create(Field.Type.STRING, "value")); Record record = RecordCreator.create("s", "s:1"); record.set(Field.create(map)); records.add(record);/*from ww w .j a va 2 s . c o m*/ map = new LinkedHashMap<>(); map.put("id", Field.create(Field.Type.INTEGER, 2)); record = RecordCreator.create("s", "s:1"); record.set(Field.create(map)); records.add(record); processRecords(processor, hiveTarget, records); assertQueryResult("select * from tbl order by id", new QueryValidator() { @Override public void validateResultSet(ResultSet rs) throws Exception { assertResultSetStructure(rs, new ImmutablePair("tbl.id", Types.INTEGER), new ImmutablePair("tbl.removed", Types.VARCHAR), new ImmutablePair("tbl.dt", Types.VARCHAR)); Assert.assertTrue("Table tbl doesn't contain any rows", rs.next()); Assert.assertEquals(1, rs.getLong(1)); Assert.assertEquals("value", rs.getString(2)); Assert.assertTrue("Unexpected number of rows", rs.next()); Assert.assertEquals(2, rs.getLong(1)); Assert.assertEquals(null, rs.getString(2)); Assert.assertFalse("Unexpected number of rows", rs.next()); } }); }
From source file:cn.gov.scciq.timer.acceptOrder.FRMDao.java
/** * ??/*from w w w. j a v a 2s .c om*/ */ public static int declFlagAction(String declNo) { int retCode = -1; Connection conn = null; CallableStatement proc = null; String call = "{call Pro_DeclFlagAction(?,?)}"; try { conn = DBPool.ds.getConnection(); proc = conn.prepareCall(call); proc.setString(1, declNo); proc.registerOutParameter(2, Types.INTEGER); proc.execute(); retCode = proc.getInt(2); } catch (SQLException e) { // TODO Auto-generated catch block log.error("N33", e); } catch (Exception e) { log.error("N34", e); } finally { try { if (proc != null) { proc.close(); } if (conn != null) { conn.close(); } } catch (SQLException e) { // TODO Auto-generated catch block log.error("N35", e); } } return retCode; }
From source file:com.liferay.portal.upgrade.util.Table.java
public Object getValue(ResultSet rs, String name, Integer type) throws Exception { Object value = null;/*from w w w . j a v a 2 s .com*/ int t = type.intValue(); if (t == Types.BIGINT) { try { value = GetterUtil.getLong(rs.getLong(name)); } catch (SQLException e) { value = GetterUtil.getLong(rs.getString(name)); } } else if (t == Types.BOOLEAN) { value = GetterUtil.getBoolean(rs.getBoolean(name)); } else if (t == Types.CLOB) { try { Clob clob = rs.getClob(name); if (clob == null) { value = StringPool.BLANK; } else { UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(clob.getCharacterStream()); StringBundler sb = new StringBundler(); String line = null; while ((line = unsyncBufferedReader.readLine()) != null) { if (sb.length() != 0) { sb.append(SAFE_NEWLINE_CHARACTER); } sb.append(line); } value = sb.toString(); } } catch (Exception e) { // If the database doesn't allow CLOB types for the column // value, then try retrieving it as a String value = GetterUtil.getString(rs.getString(name)); } } else if (t == Types.DOUBLE) { value = GetterUtil.getDouble(rs.getDouble(name)); } else if (t == Types.FLOAT) { value = GetterUtil.getFloat(rs.getFloat(name)); } else if (t == Types.INTEGER) { value = GetterUtil.getInteger(rs.getInt(name)); } else if (t == Types.SMALLINT) { value = GetterUtil.getShort(rs.getShort(name)); } else if (t == Types.TIMESTAMP) { try { value = rs.getTimestamp(name); } catch (Exception e) { } if (value == null) { value = StringPool.NULL; } } else if (t == Types.VARCHAR) { value = GetterUtil.getString(rs.getString(name)); } else { throw new UpgradeException("Upgrade code using unsupported class type " + type); } return value; }