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:com.google.visualization.datasource.util.SqlDataSourceHelper.java
/** * Converts the given SQL type to a value type. * * @param sqlType The sql type to be converted. * * @return The value type that fits the given sql type. *///from w w w .jav a2 s. c om private static ValueType sqlTypeToValueType(int sqlType) { ValueType valueType; switch (sqlType) { case Types.BOOLEAN: case Types.BIT: { valueType = ValueType.BOOLEAN; break; } case Types.CHAR: case Types.VARCHAR: valueType = ValueType.TEXT; break; case Types.INTEGER: case Types.SMALLINT: case Types.BIGINT: case Types.TINYINT: case Types.REAL: case Types.NUMERIC: case Types.DOUBLE: case Types.FLOAT: case Types.DECIMAL: valueType = ValueType.NUMBER; break; case Types.DATE: valueType = ValueType.DATE; break; case Types.TIME: valueType = ValueType.TIMEOFDAY; break; case Types.TIMESTAMP: valueType = ValueType.DATETIME; break; default: valueType = ValueType.TEXT; break; } return valueType; }
From source file:architecture.user.dao.impl.ExternalJdbcUserDao.java
public int getUserCount(Company company) { return getExtendedJdbcTemplate().queryForInt(getSql("COUNT_COMPANY_USERS"), new SqlParameterValue(Types.INTEGER, company.getCompanyId())); }
From source file:com.zimbra.cs.db.DbMailItem.java
public static void icopy(MailItem source, UnderlyingData data, boolean shared) throws ServiceException { Mailbox mbox = source.getMailbox();//w w w . j a v a 2 s . c om if (data == null || data.id <= 0 || data.folderId <= 0 || data.parentId == 0) { throw ServiceException.FAILURE("invalid data for DB item i-copy", null); } checkNamingConstraint(mbox, data.folderId, source.getName(), data.id); DbConnection conn = mbox.getOperationConnection(); PreparedStatement stmt = null; try { String table = getMailItemTableName(mbox); String mailbox_id = DebugConfig.disableMailboxGroups ? "" : "mailbox_id, "; String flags; if (!shared) { flags = "flags"; } else if (Db.supports(Db.Capability.BITWISE_OPERATIONS)) { flags = "flags | " + Flag.BITMASK_COPIED; } else { flags = "CASE WHEN " + Db.getInstance().bitAND("flags", String.valueOf(Flag.BITMASK_COPIED)) + " <> 0 THEN flags ELSE flags + " + Flag.BITMASK_COPIED + " END"; } stmt = conn.prepareStatement("INSERT INTO " + table + "(" + mailbox_id + " id, type, parent_id, folder_id, prev_folders, index_id, imap_id, date, size, locator, blob_digest," + " unread, flags, tag_names, sender, subject, name, metadata, mod_metadata, change_date, mod_content) " + "SELECT " + mailbox_id + " ?, type, parent_id, ?, ?, ?, ?, date, size, ?, blob_digest," + " unread, " + flags + ", tag_names, sender, subject, name, metadata, ?, ?, ? FROM " + table + " WHERE " + IN_THIS_MAILBOX_AND + "id = ?"); int pos = 1; stmt.setInt(pos++, data.id); // ID stmt.setInt(pos++, data.folderId); // FOLDER_ID stmt.setString(pos++, data.getPrevFolders()); if (data.indexId == MailItem.IndexStatus.NO.id()) { stmt.setNull(pos++, Types.INTEGER); } else { stmt.setInt(pos++, data.indexId); } stmt.setInt(pos++, data.imapId); // IMAP_ID stmt.setString(pos++, data.locator); stmt.setInt(pos++, mbox.getOperationChangeID()); // MOD_METADATA stmt.setInt(pos++, mbox.getOperationTimestamp()); // CHANGE_DATE stmt.setInt(pos++, mbox.getOperationChangeID()); // MOD_CONTENT pos = setMailboxId(stmt, mbox, pos); stmt.setInt(pos++, source.getId()); stmt.executeUpdate(); stmt.close(); boolean needsTag = shared && !source.isTagged(Flag.FlagInfo.COPIED); if (needsTag || source.getParentId() > 0) { boolean altersMODSEQ = source.getParentId() > 0; String updateChangeID = (altersMODSEQ ? ", mod_metadata = ?, change_date = ?" : ""); stmt = conn.prepareStatement("UPDATE " + table + " SET parent_id = NULL, flags = " + flags + updateChangeID + " WHERE " + IN_THIS_MAILBOX_AND + "id = ?"); pos = 1; if (altersMODSEQ) { stmt.setInt(pos++, mbox.getOperationChangeID()); stmt.setInt(pos++, mbox.getOperationTimestamp()); } pos = setMailboxId(stmt, mbox, pos); stmt.setInt(pos++, source.getId()); stmt.executeUpdate(); stmt.close(); } if (source instanceof Message && source.getParentId() <= 0) { changeOpenTargets(source, data.id); } MailItem.Type type = MailItem.Type.of(data.type); DbTag.storeTagReferences(mbox, data.id, type, data.getFlags() | (shared ? Flag.BITMASK_COPIED : 0), data.unreadCount > 0); DbTag.storeTagReferences(mbox, data.id, type, data.getTags()); } catch (SQLException e) { // catch item_id uniqueness constraint violation and return failure if (Db.errorMatches(e, Db.Error.DUPLICATE_ROW)) { throw MailServiceException.ALREADY_EXISTS(data.id, e); } else { throw ServiceException.FAILURE("i-copying " + source.getType() + ": " + source.getId(), e); } } finally { DbPool.closeStatement(stmt); } }
From source file:com.mobiaware.auction.data.impl.MySqlDataServiceImpl.java
@Override public int editItem(final Item item) { int uid = -1; Connection conn = null;/*from w w w . j a va2 s.c o m*/ CallableStatement stmt = null; try { conn = _dataSource.getConnection(); stmt = conn.prepareCall("{call SP_EDITITEM (?,?,?,?,?,?,?,?,?,?,?)}"); stmt.registerOutParameter(1, Types.INTEGER); stmt.setInt(2, item.getAuctionUid()); stmt.setString(3, item.getItemNumber()); stmt.setString(4, item.getName()); stmt.setString(5, item.getDescription()); stmt.setString(6, item.getCategory()); stmt.setString(7, item.getSeller()); stmt.setDouble(8, item.getValPrice()); stmt.setDouble(9, item.getMinPrice()); stmt.setDouble(10, item.getIncPrice()); stmt.setString(11, item.getUrl()); stmt.execute(); uid = stmt.getInt(1); } catch (SQLException e) { LOG.error(Throwables.getStackTraceAsString(e)); uid = -1; } finally { DbUtils.closeQuietly(conn, stmt, null); } if (LOG.isDebugEnabled()) { LOG.debug("ITEM [method:{} result:{}]", new Object[] { "edit", uid }); } return uid; }
From source file:net.sourceforge.msscodefactory.cfinternet.v2_1.CFInternetMSSql.CFInternetMSSqlSchema.java
public boolean isSystemUser(CFInternetAuthorization Authorization) { final String S_ProcName = "isSystemUser"; if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); }/*w ww .jav a 2 s .co m*/ CallableStatement stmtSecurityCheck = null; try { final String sql = "exec sp_is_system_user ?, ?"; stmtSecurityCheck = cnx.prepareCall(sql); stmtSecurityCheck.registerOutParameter(1, java.sql.Types.INTEGER); stmtSecurityCheck.setString(2, Authorization.getSecUserId().toString()); stmtSecurityCheck.execute(); int isAuthorized = stmtSecurityCheck.getInt(1); if (isAuthorized == 0) { return (false); } else { return (true); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (stmtSecurityCheck != null) { try { stmtSecurityCheck.close(); } catch (SQLException e) { } stmtSecurityCheck = null; } } }
From source file:com.openddal.test.BaseTestCase.java
/** * Check if the result set meta data is correct. * * @param rs the result set/*from ww w.j ava 2 s . c om*/ * @param columnCount the expected column count * @param labels the expected column labels * @param datatypes the expected data types * @param precision the expected precisions * @param scale the expected scales */ protected void assertResultSetMeta(ResultSet rs, int columnCount, String[] labels, int[] datatypes, int[] precision, int[] scale) throws SQLException { ResultSetMetaData meta = rs.getMetaData(); int cc = meta.getColumnCount(); if (cc != columnCount) { fail("result set contains " + cc + " columns not " + columnCount); } for (int i = 0; i < columnCount; i++) { if (labels != null) { String l = meta.getColumnLabel(i + 1); if (!labels[i].equals(l)) { fail("column label " + i + " is " + l + " not " + labels[i]); } } if (datatypes != null) { int t = meta.getColumnType(i + 1); if (datatypes[i] != t) { fail("column datatype " + i + " is " + t + " not " + datatypes[i] + " (prec=" + meta.getPrecision(i + 1) + " scale=" + meta.getScale(i + 1) + ")"); } String typeName = meta.getColumnTypeName(i + 1); String className = meta.getColumnClassName(i + 1); switch (t) { case Types.INTEGER: Assert.assertEquals("INTEGER", typeName); Assert.assertEquals("java.lang.Integer", className); break; case Types.VARCHAR: Assert.assertEquals("VARCHAR", typeName); Assert.assertEquals("java.lang.String", className); break; case Types.SMALLINT: Assert.assertEquals("SMALLINT", typeName); Assert.assertEquals("java.lang.Short", className); break; case Types.TIMESTAMP: Assert.assertEquals("TIMESTAMP", typeName); Assert.assertEquals("java.sql.Timestamp", className); break; case Types.DECIMAL: Assert.assertEquals("DECIMAL", typeName); Assert.assertEquals("java.math.BigDecimal", className); break; default: } } if (precision != null) { int p = meta.getPrecision(i + 1); if (precision[i] != p) { fail("column precision " + i + " is " + p + " not " + precision[i]); } } if (scale != null) { int s = meta.getScale(i + 1); if (scale[i] != s) { fail("column scale " + i + " is " + s + " not " + scale[i]); } } } }
From source file:CSVWriter.java
private String getColumnValue(ResultSet rs, int colType, int colIndex) throws SQLException, IOException { String value = ""; switch (colType) { case Types.BIT: case Types.JAVA_OBJECT: value = handleObject(rs.getObject(colIndex)); break;//from w w w .j a v a2s . c om case Types.BOOLEAN: boolean b = rs.getBoolean(colIndex); value = Boolean.valueOf(b).toString(); break; case NCLOB: // todo : use rs.getNClob case Types.CLOB: Clob c = rs.getClob(colIndex); if (c != null) { value = read(c); } break; case Types.BIGINT: value = handleLong(rs, colIndex); break; case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: case Types.NUMERIC: value = handleBigDecimal(rs.getBigDecimal(colIndex)); break; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: value = handleInteger(rs, colIndex); break; case Types.DATE: value = handleDate(rs, colIndex); break; case Types.TIME: value = handleTime(rs.getTime(colIndex)); break; case Types.TIMESTAMP: value = handleTimestamp(rs.getTimestamp(colIndex)); break; case NVARCHAR: // todo : use rs.getNString case NCHAR: // todo : use rs.getNString case LONGNVARCHAR: // todo : use rs.getNString case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: value = rs.getString(colIndex); break; default: value = ""; } if (value == null) { value = ""; } return value; }
From source file:net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.java
protected void setStatementParameter(int parameterIndex, Class<?> parameterType, Object parameterValue, JRPropertiesHolder properties) throws SQLException { if (java.lang.Boolean.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.BIT); } else {/* w ww.j a v a 2 s .c o m*/ statement.setBoolean(parameterIndex, (Boolean) parameterValue); } } else if (java.lang.Byte.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.TINYINT); } else { statement.setByte(parameterIndex, (Byte) parameterValue); } } else if (java.lang.Double.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.DOUBLE); } else { statement.setDouble(parameterIndex, (Double) parameterValue); } } else if (java.lang.Float.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.FLOAT); } else { statement.setFloat(parameterIndex, (Float) parameterValue); } } else if (java.lang.Integer.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.INTEGER); } else { statement.setInt(parameterIndex, (Integer) parameterValue); } } else if (java.lang.Long.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.BIGINT); } else { statement.setLong(parameterIndex, (Long) parameterValue); } } else if (java.lang.Short.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.SMALLINT); } else { statement.setShort(parameterIndex, (Short) parameterValue); } } else if (java.math.BigDecimal.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.DECIMAL); } else { statement.setBigDecimal(parameterIndex, (BigDecimal) parameterValue); } } else if (java.lang.String.class.isAssignableFrom(parameterType)) { if (parameterValue == null) { statement.setNull(parameterIndex, Types.VARCHAR); } else { statement.setString(parameterIndex, parameterValue.toString()); } } else if (java.sql.Timestamp.class.isAssignableFrom(parameterType)) { setTimestamp(parameterIndex, parameterValue, properties); } else if (java.sql.Time.class.isAssignableFrom(parameterType)) { setTime(parameterIndex, parameterValue, properties); } else if (java.util.Date.class.isAssignableFrom(parameterType)) { setDate(parameterIndex, parameterValue, properties); } else { if (isProcedureCall) { boolean handled = procedureCallHandler.setParameterValue(parameterIndex, parameterType, parameterValue); if (handled) { return; } } if (parameterValue == null) { statement.setNull(parameterIndex, Types.JAVA_OBJECT); } else { statement.setObject(parameterIndex, parameterValue); } } }
From source file:com.nextep.designer.sqlclient.ui.services.impl.SQLClientService.java
private int getSqlTypeFor(Object o) { if (o instanceof String) { return Types.VARCHAR; } else if (o instanceof Date) { return Types.DATE; } else if (o instanceof Integer) { return Types.INTEGER; } else if (o instanceof Double) { return Types.DOUBLE; } else if (o instanceof Float) { return Types.FLOAT; } else if (o instanceof BigInteger) { return Types.BIGINT; } else if (o instanceof BigDecimal) { return Types.NUMERIC; } else {/*from ww w. jav a 2 s. c o m*/ return Types.OTHER; } }
From source file:net.sourceforge.msscodefactory.cfinternet.v2_1.CFInternetSybase.CFInternetSybaseSchema.java
public boolean isSystemUser(CFInternetAuthorization Authorization) { if (!inTransaction) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), "isSystemUser", "Not in a transaction"); }/*from www .j ava 2s.co m*/ CallableStatement stmtSecurityCheck = null; try { final String sql = "{ call sp_is_system_user( ?, ? ) }"; stmtSecurityCheck = cnx.prepareCall(sql); stmtSecurityCheck.registerOutParameter(1, java.sql.Types.INTEGER); stmtSecurityCheck.setString(2, Authorization.getSecUserId().toString()); stmtSecurityCheck.execute(); int isAuthorized = stmtSecurityCheck.getInt(1); if (isAuthorized == 0) { return (false); } else { return (true); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), "isSystemUser", e); } finally { if (stmtSecurityCheck != null) { try { stmtSecurityCheck.close(); } catch (SQLException e) { } stmtSecurityCheck = null; } } }