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.jfree.data.jdbc.JDBCPieDataset.java
/** * ExecuteQuery will attempt execute the query passed to it against the * existing database connection. If no connection exists then no action * is taken.// w w w . ja v a2 s . co m * The results from the query are extracted and cached locally, thus * applying an upper limit on how many rows can be retrieved successfully. * * @param query the query to be executed * @param con the connection the query is to be executed against * * @throws SQLException if there is a problem executing the query. */ public void executeQuery(Connection con, String query) throws SQLException { Statement statement = null; ResultSet resultSet = null; try { statement = con.createStatement(); resultSet = statement.executeQuery(query); ResultSetMetaData metaData = resultSet.getMetaData(); int columnCount = metaData.getColumnCount(); if (columnCount != 2) { throw new SQLException("Invalid sql generated. PieDataSet requires 2 columns only"); } int columnType = metaData.getColumnType(2); double value = Double.NaN; while (resultSet.next()) { Comparable key = resultSet.getString(1); switch (columnType) { case Types.NUMERIC: case Types.REAL: case Types.INTEGER: case Types.DOUBLE: case Types.FLOAT: case Types.DECIMAL: case Types.BIGINT: value = resultSet.getDouble(2); setValue(key, value); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: Timestamp date = resultSet.getTimestamp(2); value = date.getTime(); setValue(key, value); break; default: System.err.println("JDBCPieDataset - unknown data type"); break; } } fireDatasetChanged(new DatasetChangeInfo()); //TODO: fill in real change info } finally { if (resultSet != null) { try { resultSet.close(); } catch (Exception e) { System.err.println("JDBCPieDataset: swallowing exception."); } } if (statement != null) { try { statement.close(); } catch (Exception e) { System.err.println("JDBCPieDataset: swallowing exception."); } } } }
From source file:com.alibaba.otter.node.etl.extract.DatabaseExtractorTest.java
private List<EventColumn> getColumn(int value) { List<EventColumn> result = new ArrayList<EventColumn>(); result.add(buildColumn("id", Types.INTEGER, "" + value, true, false)); result.add(buildColumn("name", Types.VARCHAR, "ljh_" + value, true, false)); result.add(buildColumn("alias_name", Types.CHAR, "hello_" + value, false, false)); result.add(buildColumn("amount", Types.DECIMAL, "100.01", false, false)); result.add(buildColumn("text_b", Types.BLOB, "[116,101,120,116,95,98]", false, false)); result.add(buildColumn("text_c", Types.CLOB, "", false, false)); result.add(buildColumn("curr_date", Types.DATE, "2011-01-01", false, false)); result.add(buildColumn("gmt_create", Types.TIMESTAMP, "2011-01-01 11:11:11", false, false)); result.add(buildColumn("gmt_modify", Types.TIMESTAMP, "2011-01-01 11:11:11", false, false)); return result; }
From source file:com.squid.core.domain.operators.ExtendedType.java
@JsonIgnore public boolean isInteger() { switch (this.dataType) { case Types.BIGINT: case Types.INTEGER: case Types.SMALLINT: case Types.TINYINT: return true; case Types.NUMERIC: case Types.DECIMAL: return scale == 0; default://from w w w .java 2 s .c o m return false; } }
From source file:net.sourceforge.msscodefactory.cfcore.v2_0.CFGenKbOracle.CFGenKbOracleGelExpansionTable.java
public void createGelExpansion(CFGenKbAuthorization Authorization, CFGenKbGelExpansionBuff Buff) { final String S_ProcName = "createGelExpansion"; ResultSet resultSet = null;//from w w w . j ava 2s .c o m CallableStatement stmtCreateByPKey = null; try { String ClassCode = Buff.getClassCode(); long TenantId = Buff.getRequiredTenantId(); long CartridgeId = Buff.getRequiredCartridgeId(); Integer CallerId = Buff.getOptionalCallerId(); Integer PrevId = Buff.getOptionalPrevId(); Integer NextId = Buff.getOptionalNextId(); String SourceText = Buff.getRequiredSourceText(); String MacroName = Buff.getRequiredMacroName(); Connection cnx = schema.getCnx(); stmtCreateByPKey = cnx.prepareCall("begin " + schema.getLowerSchemaDbName() + ".crt_gelexpansion( ?, ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + " ); end;"); int argIdx = 1; stmtCreateByPKey.registerOutParameter(argIdx++, OracleTypes.CURSOR); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecUserId().toString()); stmtCreateByPKey.setString(argIdx++, (Authorization == null) ? "" : Authorization.getSecSessionId().toString()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecClusterId()); stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); stmtCreateByPKey.setString(argIdx++, ClassCode); stmtCreateByPKey.setLong(argIdx++, TenantId); stmtCreateByPKey.setLong(argIdx++, CartridgeId); if (CallerId != null) { stmtCreateByPKey.setInt(argIdx++, CallerId.intValue()); } else { stmtCreateByPKey.setNull(argIdx++, java.sql.Types.INTEGER); } if (PrevId != null) { stmtCreateByPKey.setInt(argIdx++, PrevId.intValue()); } else { stmtCreateByPKey.setNull(argIdx++, java.sql.Types.INTEGER); } if (NextId != null) { stmtCreateByPKey.setInt(argIdx++, NextId.intValue()); } else { stmtCreateByPKey.setNull(argIdx++, java.sql.Types.INTEGER); } stmtCreateByPKey.setString(argIdx++, SourceText); stmtCreateByPKey.setString(argIdx++, MacroName); stmtCreateByPKey.execute(); resultSet = (ResultSet) stmtCreateByPKey.getObject(1); if (resultSet == null) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "crt_gelexpansion() did not return a result set"); } try { if (resultSet.next()) { CFGenKbGelExpansionBuff createdBuff = unpackGelExpansionResultSetToBuff(resultSet); if (resultSet.next()) { resultSet.last(); throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Did not expect multi-record response, " + resultSet.getRow() + " rows selected"); } Buff.setRequiredTenantId(createdBuff.getRequiredTenantId()); Buff.setRequiredCartridgeId(createdBuff.getRequiredCartridgeId()); Buff.setRequiredGelInstId(createdBuff.getRequiredGelInstId()); Buff.setOptionalCallerId(createdBuff.getOptionalCallerId()); Buff.setOptionalPrevId(createdBuff.getOptionalPrevId()); Buff.setOptionalNextId(createdBuff.getOptionalNextId()); Buff.setRequiredSourceText(createdBuff.getRequiredSourceText()); Buff.setRequiredRevision(createdBuff.getRequiredRevision()); Buff.setRequiredMacroName(createdBuff.getRequiredMacroName()); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected a single-record response, " + resultSet.getRow() + " rows selected"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "crt_gelexpansion() did not return a valid result set"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } if (stmtCreateByPKey != null) { try { stmtCreateByPKey.close(); } catch (SQLException e) { } stmtCreateByPKey = null; } } }
From source file:com.cloud.upgrade.dao.Upgrade421to430.java
private void encryptLdapConfigParams(Connection conn) { String[][] ldapParams = {// ww w . j av a 2 s . c om { "ldap.user.object", "inetOrgPerson", "Sets the object type of users within LDAP" }, { "ldap.username.attribute", "uid", "Sets the username attribute used within LDAP" }, { "ldap.email.attribute", "mail", "Sets the email attribute used within LDAP" }, { "ldap.firstname.attribute", "givenname", "Sets the firstname attribute used within LDAP" }, { "ldap.lastname.attribute", "sn", "Sets the lastname attribute used within LDAP" }, { "ldap.group.object", "groupOfUniqueNames", "Sets the object type of groups within LDAP" }, { "ldap.group.user.uniquemember", "uniquemember", "Sets the attribute for uniquemembers within a group" } }; String insertSql = "INSERT INTO `cloud`.`configuration`(category, instance, component, name, value, description) VALUES ('Secure', 'DEFAULT', 'management-server', ?, ?, " + "?) ON DUPLICATE KEY UPDATE category='Secure';"; try (PreparedStatement pstmt_insert_ldap_parameters = conn.prepareStatement(insertSql);) { for (String[] ldapParam : ldapParams) { String name = ldapParam[0]; String value = ldapParam[1]; String desc = ldapParam[2]; String encryptedValue = DBEncryptionUtil.encrypt(value); pstmt_insert_ldap_parameters.setString(1, name); pstmt_insert_ldap_parameters.setBytes(2, encryptedValue.getBytes("UTF-8")); pstmt_insert_ldap_parameters.setString(3, desc); pstmt_insert_ldap_parameters.executeUpdate(); } /** * if encrypted, decrypt the ldap hostname and port and then update as they are not encrypted now. */ try (PreparedStatement pstmt_ldap_hostname = conn.prepareStatement( "SELECT conf.value FROM `cloud`.`configuration` conf WHERE conf.name='ldap.hostname'"); ResultSet resultSet_ldap_hostname = pstmt_ldap_hostname.executeQuery();) { String hostname = null; String port; int portNumber = 0; if (resultSet_ldap_hostname.next()) { hostname = DBEncryptionUtil.decrypt(resultSet_ldap_hostname.getString(1)); } try (PreparedStatement pstmt_ldap_port = conn.prepareStatement( "SELECT conf.value FROM `cloud`.`configuration` conf WHERE conf.name='ldap.port'"); ResultSet resultSet_ldap_port = pstmt_ldap_port.executeQuery();) { if (resultSet_ldap_port.next()) { port = DBEncryptionUtil.decrypt(resultSet_ldap_port.getString(1)); if (StringUtils.isNotBlank(port)) { portNumber = Integer.parseInt(port); } } if (StringUtils.isNotBlank(hostname)) { try (PreparedStatement pstmt_insert_ldap_hostname_port = conn.prepareStatement( "INSERT INTO `cloud`.`ldap_configuration`(hostname, port) VALUES(?,?)");) { pstmt_insert_ldap_hostname_port.setString(1, hostname); if (portNumber != 0) { pstmt_insert_ldap_hostname_port.setInt(2, portNumber); } else { pstmt_insert_ldap_hostname_port.setNull(2, Types.INTEGER); } pstmt_insert_ldap_hostname_port.executeUpdate(); } } } } } catch (SQLException e) { throw new CloudRuntimeException("Unable to insert ldap configuration values ", e); } catch (UnsupportedEncodingException e) { throw new CloudRuntimeException("Unable to insert ldap configuration values ", e); } s_logger.debug("Done encrypting ldap Config values"); }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlAttachmentTable.java
public void createAttachment(CFAccAuthorization Authorization, CFAccAttachmentBuff Buff) { final String S_ProcName = "createAttachment"; if ("ATTC".equals(Buff.getClassCode()) && (!schema.isTenantUser(Authorization, Buff.getRequiredTenantId(), "CreateAttachment"))) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Permission denied -- User not part of TSecGroup CreateAttachment"); }//from w w w.ja v a2 s.com if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); } try { Connection cnx = schema.getCnx(); long TenantId = Buff.getRequiredTenantId(); long AttachmentId = schema.getTableTenant().nextAttachmentIdGen(Authorization, Buff.getRequiredTenantId()); long ContactId = Buff.getRequiredContactId(); String Description = Buff.getRequiredDescription(); Integer MimeTypeId = Buff.getOptionalMimeTypeId(); String Attachment = Buff.getRequiredAttachment(); int Revision = 1; String sql = "INSERT INTO " + schema.getLowerSchemaDbName() + "..Attchmnt( " + "forcesynclock, " + "createdby, " + "createdat, " + "updatedby, " + "updatedat, " + "tenantid, " + "attachmentid, " + "contactid, " + "description, " + "mimetypeid, " + "attachment" + ", revision )" + "VALUES ( " + "0, " + " ?, " + " getdate(), " + " ?, " + " getdate(), " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "1 )"; if (stmtCreateByPKey == null) { stmtCreateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtCreateByPKey.setString(argIdx++, Authorization.getSecUserId().toString()); stmtCreateByPKey.setString(argIdx++, Authorization.getSecUserId().toString()); stmtCreateByPKey.setLong(argIdx++, TenantId); stmtCreateByPKey.setLong(argIdx++, AttachmentId); stmtCreateByPKey.setLong(argIdx++, ContactId); stmtCreateByPKey.setString(argIdx++, Description); if (MimeTypeId != null) { stmtCreateByPKey.setInt(argIdx++, MimeTypeId.intValue()); } else { stmtCreateByPKey.setNull(argIdx++, java.sql.Types.INTEGER); } stmtCreateByPKey.setString(argIdx++, Attachment); int rowsAffected = stmtCreateByPKey.executeUpdate(); if (rowsAffected != 1) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 row to be affected by insert, not " + rowsAffected); } Buff.setRequiredAttachmentId(AttachmentId); Buff.setRequiredRevision(Revision); String sqlAuditCreated = "INSERT INTO " + schema.getLowerSchemaDbName() + "..Attchmnt_h( auditclusterid, " + " auditsessionid, " + " auditstamp" + ", " + "tenantid" + ", " + "attachmentid" + ", " + "contactid" + ", " + "description" + ", " + "mimetypeid" + ", " + "attachment" + ", " + " revision, " + " auditaction ) " + "SELECT ?, ?, sysdatetime()" + ", " + "attc.tenantid" + ", " + "attc.attachmentid" + ", " + "attc.contactid" + ", " + "attc.description" + ", " + "attc.mimetypeid" + ", " + "attc.attachment" + ", " + " attc.revision, " + " 1" + "FROM " + schema.getLowerSchemaDbName() + "..Attchmnt AS attc " + " WHERE " + "attc.tenantid = ? " + "AND attc.attachmentid = ? "; if (stmtAuditCreatedByPKey == null) { stmtAuditCreatedByPKey = cnx.prepareStatement(sqlAuditCreated); } argIdx = 1; stmtAuditCreatedByPKey.setLong(argIdx++, Authorization.getSecClusterId()); stmtAuditCreatedByPKey.setString(argIdx++, Authorization.getSecSessionId().toString()); stmtAuditCreatedByPKey.setLong(argIdx++, TenantId); stmtAuditCreatedByPKey.setLong(argIdx++, AttachmentId); int rowsAudited = stmtAuditCreatedByPKey.executeUpdate(); if (rowsAudited != 1) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 row to be affected by audit via insert-selected, not " + rowsAffected); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:com.fns.grivet.repo.JdbcEntityRepository.java
@Override public List<EntityAttributeValue> executeDynamicQuery(Integer cid, DynamicQuery query) { Assert.isTrue(query.areConjunctionsHomogenous(), "Query cannot be executed! All conjunctions must be homogenous!"); String sql = QueryBuilder.newInstance().append(query).build(); log.trace(String.format("JdbcEntityRepository.executeDynamicQuery[sql=%s]", sql)); List<SqlParameterValue> values = new ArrayList<>(); values.add(new SqlParameterValue(Types.INTEGER, cid)); values.addAll(Arrays.asList(query.asSqlParameterValues())); return mapRows(jdbcTemplate.query(sql, new SqlRowSetResultSetExtractor(), values.toArray(new Object[values.size()]))); }
From source file:Main.java
private static Vector getDataTypes(Connection con) throws SQLException { String structName = null, distinctName = null, javaName = null; // create a vector of class DataType initialized with // the SQL code, the SQL type name, and two null entries // for the local type name and the creation parameter(s) Vector dataTypes = new Vector(); dataTypes.add(new DataType(java.sql.Types.BIT, "BIT")); dataTypes.add(new DataType(java.sql.Types.TINYINT, "TINYINT")); dataTypes.add(new DataType(java.sql.Types.SMALLINT, "SMALLINT")); dataTypes.add(new DataType(java.sql.Types.INTEGER, "INTEGER")); dataTypes.add(new DataType(java.sql.Types.BIGINT, "BIGINT")); dataTypes.add(new DataType(java.sql.Types.FLOAT, "FLOAT")); dataTypes.add(new DataType(java.sql.Types.REAL, "REAL")); dataTypes.add(new DataType(java.sql.Types.DOUBLE, "DOUBLE")); dataTypes.add(new DataType(java.sql.Types.NUMERIC, "NUMERIC")); dataTypes.add(new DataType(java.sql.Types.DECIMAL, "DECIMAL")); dataTypes.add(new DataType(java.sql.Types.CHAR, "CHAR")); dataTypes.add(new DataType(java.sql.Types.VARCHAR, "VARCHAR")); dataTypes.add(new DataType(java.sql.Types.LONGVARCHAR, "LONGVARCHAR")); dataTypes.add(new DataType(java.sql.Types.DATE, "DATE")); dataTypes.add(new DataType(java.sql.Types.TIME, "TIME")); dataTypes.add(new DataType(java.sql.Types.TIMESTAMP, "TIMESTAMP")); dataTypes.add(new DataType(java.sql.Types.BINARY, "BINARY")); dataTypes.add(new DataType(java.sql.Types.VARBINARY, "VARBINARY")); dataTypes.add(new DataType(java.sql.Types.LONGVARBINARY, "LONGVARBINARY")); dataTypes.add(new DataType(java.sql.Types.NULL, "NULL")); dataTypes.add(new DataType(java.sql.Types.OTHER, "OTHER")); dataTypes.add(new DataType(java.sql.Types.BLOB, "BLOB")); dataTypes.add(new DataType(java.sql.Types.CLOB, "CLOB")); DatabaseMetaData dbmd = con.getMetaData(); ResultSet rs = dbmd.getTypeInfo(); while (rs.next()) { int codeNumber = rs.getInt("DATA_TYPE"); String dbmsName = rs.getString("TYPE_NAME"); String createParams = rs.getString("CREATE_PARAMS"); if (codeNumber == Types.STRUCT && structName == null) structName = dbmsName;//from w w w . j a v a2 s.com else if (codeNumber == Types.DISTINCT && distinctName == null) distinctName = dbmsName; else if (codeNumber == Types.JAVA_OBJECT && javaName == null) javaName = dbmsName; else { for (int i = 0; i < dataTypes.size(); i++) { // find entry that matches the SQL code, // and if local type and params are not already set, // set them DataType type = (DataType) dataTypes.get(i); if (type.getCode() == codeNumber) { type.setLocalTypeAndParams(dbmsName, createParams); } } } } int[] types = { Types.STRUCT, Types.DISTINCT, Types.JAVA_OBJECT }; rs = dbmd.getUDTs(null, "%", "%", types); while (rs.next()) { String typeName = null; DataType dataType = null; if (dbmd.isCatalogAtStart()) typeName = rs.getString(1) + dbmd.getCatalogSeparator() + rs.getString(2) + "." + rs.getString(3); else typeName = rs.getString(2) + "." + rs.getString(3) + dbmd.getCatalogSeparator() + rs.getString(1); switch (rs.getInt(5)) { case Types.STRUCT: dataType = new DataType(Types.STRUCT, typeName); dataType.setLocalTypeAndParams(structName, null); break; case Types.DISTINCT: dataType = new DataType(Types.DISTINCT, typeName); dataType.setLocalTypeAndParams(distinctName, null); break; case Types.JAVA_OBJECT: dataType = new DataType(Types.JAVA_OBJECT, typeName); dataType.setLocalTypeAndParams(javaName, null); break; } dataTypes.add(dataType); } return dataTypes; }
From source file:com.serotonin.mango.db.dao.UserDao.java
void updateUser(User user) { // potential fix or "An attempt was made to get a data value of type 'VARCHAR' from a data value of type 'null'" if (user.getPhone() == null) user.setPhone(""); if (user.getHomeUrl() == null) user.setHomeUrl(""); try {/*w w w .j a v a2 s .c om*/ ejt.update(USER_UPDATE, new Object[] { user.getUsername(), user.getPassword(), user.getEmail(), user.getPhone(), boolToChar(user.isAdmin()), boolToChar(user.isDisabled()), user.getHomeUrl(), user.getReceiveAlarmEmails(), boolToChar(user.isReceiveOwnAuditEvents()), user.getId() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.VARCHAR, Types.INTEGER }); saveRelationalData(user); } catch (DataAccessException e) { LOG.error("Error updating user: " + user, e); throw e; } }
From source file:com.bt.aloha.dao.StateInfoDaoImpl.java
public void replace(final T info) { if (info == null) throw new IllegalArgumentException("Cannot replace null info object in collection."); T newInfo = info.cloneObject();/* www . ja va 2 s . c om*/ newInfo.updateVersionId(); newInfo.updateLastUsedTime(); int updated = 0; try { Object[] params = new Object[] { newInfo.getVersionId(), newInfo.getLastUsedTime(), newInfo.isDead() ? 1 : 0, new SqlLobValue(new ObjectSerialiser().serialise(newInfo)), info.getId(), info.getVersionId(), }; int[] types = new int[] { Types.VARCHAR, Types.BIGINT, Types.INTEGER, Types.BLOB, Types.VARCHAR, Types.VARCHAR }; updated = getJdbcTemplate().update(UPDATE_SQL, params, types); } catch (DataAccessException e) { throw new IllegalArgumentException(String.format("Cannot update info %s in database", info.getId()), e); } if (updated == 0) throw new ConcurrentUpdateException(info.getId(), String.format("Info %s modified in database, try again", info.getId())); info.setVersionId(newInfo.getVersionId()); info.setLastUsedTime(newInfo.getLastUsedTime()); }