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.connsec.authentication.AcceptJdbcUsersAuthenticationHandler.java
/** * login log write to log db/*from ww w . ja v a2s .c o m*/ * @param uid * @param j_username * @param type * @param code * @param message */ public boolean insertLoginHistory(UserInfo userInfo, String type, String provider, String code, String message) { Date loginDate = new Date(); String sessionId = WebContext.genId(); WebContext.setAttribute(WebConstants.CURRENT_USER_SESSION_ID, sessionId); String ipAddress = WebContext.getRequestIpAddress(); String platform = ""; String browser = ""; String userAgent = WebContext.getRequest().getHeader("User-Agent"); String[] arrayUserAgent = null; if (userAgent.indexOf("MSIE") > 0) { arrayUserAgent = userAgent.split(";"); browser = arrayUserAgent[1].trim(); platform = arrayUserAgent[2].trim(); } else if (userAgent.indexOf("Trident") > 0) { arrayUserAgent = userAgent.split(";"); browser = "MSIE/" + arrayUserAgent[3].split("\\)")[0]; ; platform = arrayUserAgent[0].split("\\(")[1]; } else if (userAgent.indexOf("Chrome") > 0) { arrayUserAgent = userAgent.split(" "); //browser=arrayUserAgent[8].trim(); for (int i = 0; i < arrayUserAgent.length; i++) { if (arrayUserAgent[i].contains("Chrome")) { browser = arrayUserAgent[i].trim(); browser = browser.substring(0, browser.indexOf('.')); } } platform = (arrayUserAgent[1].substring(1) + " " + arrayUserAgent[2] + " " + arrayUserAgent[3].substring(0, arrayUserAgent[3].length() - 1)).trim(); } else if (userAgent.indexOf("Firefox") > 0) { arrayUserAgent = userAgent.split(" "); for (int i = 0; i < arrayUserAgent.length; i++) { if (arrayUserAgent[i].contains("Firefox")) { browser = arrayUserAgent[i].trim(); browser = browser.substring(0, browser.indexOf('.')); } } platform = (arrayUserAgent[1].substring(1) + " " + arrayUserAgent[2] + " " + arrayUserAgent[3].substring(0, arrayUserAgent[3].length() - 1)).trim(); } jdbcTemplate.update(HISTORY_LOGIN_INSERT_STATEMENT, new Object[] { WebContext.genId(), sessionId, userInfo.getId(), userInfo.getUsername(), userInfo.getDisplayName(), type, message, code, provider, ipAddress, browser, platform, "Browser", loginDate }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP }); userInfo.setLastLoginTime(new SimpleDateFormat(FORMAT_DATE_YYYY_MM_DD_HH_MM_SS).format(loginDate)); jdbcTemplate.update(LOGIN_USERINFO_UPDATE_STATEMENT, new Object[] { loginDate, ipAddress, userInfo.getLoginCount() + 1, userInfo.getId() }, new int[] { Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.VARCHAR }); return true; }
From source file:org.owasp.proxy.http.dao.JdbcMessageDAO.java
public boolean deleteConversation(int id) throws DataAccessException { MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(ID, id, Types.INTEGER); return getNamedParameterJdbcTemplate().update(DELETE_CONVERSATION, params) > 0; }
From source file:madgik.exareme.master.queryProcessor.analyzer.stat.ExternalStat.java
private int computeColumnSize(String columnName, int columnType, String table_sample) throws Exception { int columnSize = 0; if (columnType == Types.INTEGER || columnType == Types.REAL || columnType == Types.DOUBLE || columnType == Types.DECIMAL || columnType == Types.FLOAT || columnType == Types.NUMERIC) { columnSize = NUM_SIZE;/*from w ww .j a v a 2s .c o m*/ } else if (columnType == Types.VARCHAR) { String query0 = "select max(length(" + columnName + ")) as length from (select " + columnName + " from " + table_sample + ") A" + " where " + columnName + " is not null limit " + MAX_STRING_SAMPLE; if (con.getClass().getName().contains("oracle")) { query0 = "select max(length(" + columnName + ")) as length from (select " + columnName + " from " + table_sample + ") A" + " where " + columnName + " is not null and ROWNUM< " + MAX_STRING_SAMPLE; } log.debug("executing col size query:" + query0); Statement stmt0 = con.createStatement(); ResultSet rs0 = stmt0.executeQuery(query0); while (rs0.next()) { columnSize = rs0.getInt("length"); } rs0.close(); stmt0.close(); } else if (columnType == Types.BLOB) columnSize = BLOB_SIZE; return columnSize; }
From source file:com.flexive.core.storage.GenericDivisionExporter.java
/** * Dump a generic table to XML// www.j av a 2 s .co m * * @param tableName name of the table * @param stmt an open statement * @param out output stream * @param sb an available and valid StringBuilder * @param xmlTag name of the xml tag to write per row * @param idColumn (optional) id column to sort results * @param onlyBinaries process binary fields (else these will be ignored) * @throws SQLException on errors * @throws IOException on errors */ private void dumpTable(String tableName, Statement stmt, OutputStream out, StringBuilder sb, String xmlTag, String idColumn, boolean onlyBinaries) throws SQLException, IOException { ResultSet rs = stmt.executeQuery("SELECT * FROM " + tableName + (StringUtils.isEmpty(idColumn) ? "" : " ORDER BY " + idColumn + " ASC")); final ResultSetMetaData md = rs.getMetaData(); String value, att; boolean hasSubTags; while (rs.next()) { hasSubTags = false; if (!onlyBinaries) { sb.setLength(0); sb.append(" <").append(xmlTag); } for (int i = 1; i <= md.getColumnCount(); i++) { value = null; att = md.getColumnName(i).toLowerCase(); switch (md.getColumnType(i)) { case java.sql.Types.DECIMAL: case java.sql.Types.NUMERIC: case java.sql.Types.BIGINT: if (!onlyBinaries) { value = String.valueOf(rs.getBigDecimal(i)); if (rs.wasNull()) value = null; } break; case java.sql.Types.INTEGER: case java.sql.Types.SMALLINT: case java.sql.Types.TINYINT: if (!onlyBinaries) { value = String.valueOf(rs.getLong(i)); if (rs.wasNull()) value = null; } break; case java.sql.Types.DOUBLE: case java.sql.Types.FLOAT: case java.sql.Types.REAL: if (!onlyBinaries) { value = String.valueOf(rs.getDouble(i)); if (rs.wasNull()) value = null; } break; case java.sql.Types.TIMESTAMP: case java.sql.Types.DATE: if (!onlyBinaries) { final Timestamp ts = rs.getTimestamp(i); if (rs.wasNull()) value = null; else value = FxFormatUtils.getDateTimeFormat().format(ts); } break; case java.sql.Types.BIT: case java.sql.Types.CHAR: case java.sql.Types.BOOLEAN: if (!onlyBinaries) { value = rs.getBoolean(i) ? "1" : "0"; if (rs.wasNull()) value = null; } break; case java.sql.Types.CLOB: case java.sql.Types.BLOB: case java.sql.Types.LONGVARBINARY: case java.sql.Types.LONGVARCHAR: case java.sql.Types.VARBINARY: case java.sql.Types.VARCHAR: case java.sql.Types.BINARY: case SQL_LONGNVARCHAR: case SQL_NCHAR: case SQL_NCLOB: case SQL_NVARCHAR: hasSubTags = true; break; default: LOG.warn("Unhandled type [" + md.getColumnType(i) + "] for [" + tableName + "." + att + "]"); } if (value != null && !onlyBinaries) sb.append(' ').append(att).append("=\"").append(value).append("\""); } if (hasSubTags) { if (!onlyBinaries) sb.append(">\n"); for (int i = 1; i <= md.getColumnCount(); i++) { switch (md.getColumnType(i)) { case java.sql.Types.VARBINARY: case java.sql.Types.LONGVARBINARY: case java.sql.Types.BLOB: case java.sql.Types.BINARY: if (idColumn == null) throw new IllegalArgumentException("Id column required to process binaries!"); String binFile = FOLDER_BINARY + "/BIN_" + String.valueOf(rs.getLong(idColumn)) + "_" + i + ".blob"; att = md.getColumnName(i).toLowerCase(); if (onlyBinaries) { if (!(out instanceof ZipOutputStream)) throw new IllegalArgumentException( "out has to be a ZipOutputStream to store binaries!"); ZipOutputStream zip = (ZipOutputStream) out; InputStream in = rs.getBinaryStream(i); if (rs.wasNull()) break; ZipEntry ze = new ZipEntry(binFile); zip.putNextEntry(ze); byte[] buffer = new byte[4096]; int read; while ((read = in.read(buffer)) != -1) zip.write(buffer, 0, read); in.close(); zip.closeEntry(); zip.flush(); } else { InputStream in = rs.getBinaryStream(i); //need to fetch to see if it is empty if (rs.wasNull()) break; in.close(); sb.append(" <").append(att).append(">").append(binFile).append("</").append(att) .append(">\n"); } break; case java.sql.Types.CLOB: case SQL_LONGNVARCHAR: case SQL_NCHAR: case SQL_NCLOB: case SQL_NVARCHAR: case java.sql.Types.LONGVARCHAR: case java.sql.Types.VARCHAR: if (!onlyBinaries) { value = rs.getString(i); if (rs.wasNull()) break; att = md.getColumnName(i).toLowerCase(); sb.append(" <").append(att).append('>'); escape(sb, value); sb.append("</").append(att).append(">\n"); } break; } } if (!onlyBinaries) sb.append(" </").append(xmlTag).append(">\n"); } else { if (!onlyBinaries) sb.append("/>\n"); } if (!onlyBinaries) write(out, sb); } }
From source file:de.whs.poodle.repositories.EvaluationWorksheetRepository.java
@Transactional public int addQuestionToSection(int evaluationSectionId, EvaluationQuestion question) { // question itself int questionId = jdbc.queryForObject( "INSERT INTO evaluation_question(evaluation_section_id,number,text,allow_not_applicable) VALUES(?,?,?,?) RETURNING id", new Object[] { evaluationSectionId, question.getNumber(), question.getText(), question.isAllowNotApplicable() }, Integer.class); // choices (if any) for (EvaluationQuestionChoice choice : question.getChoices()) { jdbc.update(//from w w w .j av a2 s.co m "INSERT INTO evaluation_question_to_choice(evaluation_question_id,value,text) VALUES(?,?,?)", new Object[] { questionId, choice.getValue(), choice.getText() }, // must specify types since value and text may be null and it can't determine the type in this case new int[] { Types.INTEGER, Types.INTEGER, Types.VARCHAR }); } return questionId; }
From source file:com.jaspersoft.jrx.query.PlSqlQueryExecuter.java
private void createStatement() throws JRException { String queryString = getQueryString(); if (connection != null && queryString != null && queryString.trim().length() > 0) { try {// www. j ava 2 s.c o m isStoredProcedure = isOracleStoredProcedure(queryString); if (isStoredProcedure) { statement = connection.prepareCall(queryString); } else { statement = connection.prepareStatement(queryString); } int fetchSize = JRPropertiesUtil.getInstance(getJasperReportsContext()).getIntegerProperty( dataset.getPropertiesMap(), JRJdbcQueryExecuterFactory.PROPERTY_JDBC_FETCH_SIZE, 0); if (fetchSize > 0) { statement.setFetchSize(fetchSize); } List<String> parameterNames = getCollectedParameterNames(); if (!parameterNames.isEmpty()) { for (int i = 0; i < parameterNames.size(); i++) { String parameterName = (String) parameterNames.get(i); JRValueParameter parameter = getValueParameter(parameterName); Class<?> clazz = parameter.getValueClass(); Object parameterValue = parameter.getValue(); if (clazz.equals(java.lang.Object.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.JAVA_OBJECT); } else { statement.setObject(i + 1, parameterValue); } } else if (clazz.equals(java.lang.Boolean.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.BIT); } else { statement.setBoolean(i + 1, ((Boolean) parameterValue).booleanValue()); } } else if (clazz.equals(java.lang.Byte.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.TINYINT); } else { statement.setByte(i + 1, ((Byte) parameterValue).byteValue()); } } else if (clazz.equals(java.lang.Double.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.DOUBLE); } else { statement.setDouble(i + 1, ((Double) parameterValue).doubleValue()); } } else if (clazz.equals(java.lang.Float.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.FLOAT); } else { statement.setFloat(i + 1, ((Float) parameterValue).floatValue()); } } else if (clazz.equals(java.lang.Integer.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.INTEGER); } else { statement.setInt(i + 1, ((Integer) parameterValue).intValue()); } } else if (clazz.equals(java.lang.Long.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.BIGINT); } else { statement.setLong(i + 1, ((Long) parameterValue).longValue()); } } else if (clazz.equals(java.lang.Short.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.SMALLINT); } else { statement.setShort(i + 1, ((Short) parameterValue).shortValue()); } } else if (clazz.equals(java.math.BigDecimal.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.DECIMAL); } else { statement.setBigDecimal(i + 1, (BigDecimal) parameterValue); } } else if (clazz.equals(java.lang.String.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.VARCHAR); } else { statement.setString(i + 1, parameterValue.toString()); } } else if (clazz.equals(java.util.Date.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.DATE); } else { statement.setDate(i + 1, new java.sql.Date(((java.util.Date) parameterValue).getTime())); } } else if (clazz.equals(java.sql.Timestamp.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.TIMESTAMP); } else { statement.setTimestamp(i + 1, (java.sql.Timestamp) parameterValue); } } else if (clazz.equals(java.sql.Time.class)) { if (parameterValue == null) { statement.setNull(i + 1, Types.TIME); } else { statement.setTime(i + 1, (java.sql.Time) parameterValue); } } else if (clazz.equals(java.sql.ResultSet.class)) { if (!isStoredProcedure) { throw new JRException("OUT paramater used in non-stored procedure call : " + parameterName + " class " + clazz.getName()); } else if (cursorParameter > 0) { throw new JRException("A stored procedure can have at most one cursor parameter : " + parameterName + " class " + clazz.getName()); } ((CallableStatement) statement).registerOutParameter(i + 1, ORACLE_CURSOR_TYPE); cursorParameter = i + 1; } else { throw new JRException("Parameter type not supported in query : " + parameterName + " class " + clazz.getName()); } } } } catch (SQLException e) { throw new JRException("Error preparing statement for executing the report query : " + "\n\n" + queryString + "\n\n", e); } } }
From source file:org.jfree.data.jdbc.JDBCCategoryDataset.java
/** * Populates the dataset by executing the supplied query against the * existing database connection. If no connection exists then no action * is taken.//w w w. j a v a 2s.com * <p> * The results from the query are extracted and cached locally, thus * applying an upper limit on how many rows can be retrieved successfully. * * @param con the connection. * @param query the query. * * @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("JDBCCategoryDataset.executeQuery() : insufficient columns " + "returned from the database."); } // Remove any previous old data int i = getRowCount(); while (--i >= 0) { removeRow(i); } while (resultSet.next()) { // first column contains the row key... Comparable rowKey = resultSet.getString(1); for (int column = 2; column <= columnCount; column++) { Comparable columnKey = metaData.getColumnName(column); int columnType = metaData.getColumnType(column); switch (columnType) { case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: case Types.FLOAT: case Types.DOUBLE: case Types.DECIMAL: case Types.NUMERIC: case Types.REAL: { Number value = (Number) resultSet.getObject(column); if (this.transpose) { setValue(value, columnKey, rowKey); } else { setValue(value, rowKey, columnKey); } break; } case Types.DATE: case Types.TIME: case Types.TIMESTAMP: { Date date = (Date) resultSet.getObject(column); Number value = new Long(date.getTime()); if (this.transpose) { setValue(value, columnKey, rowKey); } else { setValue(value, rowKey, columnKey); } break; } case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: { String string = (String) resultSet.getObject(column); try { Number value = Double.valueOf(string); if (this.transpose) { setValue(value, columnKey, rowKey); } else { setValue(value, rowKey, columnKey); } } catch (NumberFormatException e) { // suppress (value defaults to null) } break; } default: // not a value, can't use it (defaults to null) break; } } } fireDatasetChanged(new DatasetChangeInfo()); //TODO: fill in real change info } finally { if (resultSet != null) { try { resultSet.close(); } catch (Exception e) { // report this? } } if (statement != null) { try { statement.close(); } catch (Exception e) { // report this? } } } }
From source file:com.act.lcms.db.model.ScanFile.java
protected static void bindInsertOrUpdateParameters(PreparedStatement stmt, String filename, SCAN_MODE mode, SCAN_FILE_TYPE fileType, Integer plateId, Integer plateRow, Integer plateColumn) throws SQLException { stmt.setString(DB_FIELD.FILENAME.getInsertUpdateOffset(), filename); stmt.setString(DB_FIELD.MODE.getInsertUpdateOffset(), mode.name()); stmt.setString(DB_FIELD.FILE_TYPE.getInsertUpdateOffset(), fileType.name()); if (plateId != null) { stmt.setInt(DB_FIELD.PLATE_ID.getInsertUpdateOffset(), plateId); } else {// ww w .ja v a 2s. c o m stmt.setNull(DB_FIELD.PLATE_ID.getInsertUpdateOffset(), Types.INTEGER); } if (plateRow != null) { stmt.setInt(DB_FIELD.PLATE_ROW.getInsertUpdateOffset(), plateRow); } else { stmt.setNull(DB_FIELD.PLATE_ROW.getInsertUpdateOffset(), Types.INTEGER); } if (plateColumn != null) { stmt.setInt(DB_FIELD.PLATE_COLUMN.getInsertUpdateOffset(), plateColumn); } else { stmt.setNull(DB_FIELD.PLATE_COLUMN.getInsertUpdateOffset(), Types.INTEGER); } }
From source file:org.owasp.proxy.http.dao.JdbcMessageDAO.java
public Collection<Integer> listConversationsSince(int id) throws DataAccessException { MapSqlParameterSource params = new MapSqlParameterSource(); try {//ww w.j a v a 2s. c o m params.addValue(ID, id, Types.INTEGER); SimpleJdbcTemplate template = new SimpleJdbcTemplate(getNamedParameterJdbcTemplate()); return template.query(SELECT_CONVERSATIONS, ID_MAPPER, params); } catch (EmptyResultDataAccessException erdae) { return Collections.emptyList(); } }
From source file:br.bookmark.db.util.ResultSetUtils.java
/** * Map JDBC objects to Java equivalents. * Used by getBean() and getBeans().// w w w . j a va2 s. c o m * <p> * Some types not supported. * Many not work with all drivers. * <p> * Makes binary conversions of BIGINT, DATE, DECIMAL, DOUBLE, FLOAT, INTEGER, * REAL, SMALLINT, TIME, TIMESTAMP, TINYINT. * Makes Sting conversions of CHAR, CLOB, VARCHAR, LONGVARCHAR, BLOB, LONGVARBINARY, * VARBINARY. * <p> * DECIMAL, INTEGER, SMALLINT, TIMESTAMP, CHAR, VARCHAR tested with MySQL and Poolman. * Others not guaranteed. * @param classeDestino * @throws NoSuchFieldException * @throws SecurityException */ private static void putEntry(Map properties, ResultSetMetaData metaData, ResultSet resultSet, int i, Class classeDestino) throws Exception { /* In a perfect universe, this would be enough properties.put( metaData.getColumnName(i), resultSet.getObject(i)); But only String, Timestamp, and Integer seem to get through that way. */ String columnName = metaData.getColumnName(i); // Testa se uma FK /*Field[] fields = classeDestino.getDeclaredFields(); for (int j = 0; j < fields.length; j++) { if (fields[j].getAnnotation(DBFK.class) != null) { properties.put(columnName, resultSet.getString(i)); } }*/ //System.out.println(i+"-"+metaData.getColumnType(i)); switch (metaData.getColumnType(i)) { // http://java.sun.com/j2se/1.3.0/docs/api/java/sql/Types.html case Types.BIGINT: properties.put(columnName, new Long(resultSet.getLong(i))); break; case Types.DATE: properties.put(columnName, resultSet.getDate(i)); break; case Types.DECIMAL: case Types.DOUBLE: properties.put(columnName, new Double(resultSet.getDouble(i))); break; case Types.FLOAT: properties.put(columnName, new Float(resultSet.getFloat(i))); break; case Types.INTEGER: int valor = 0; try { // Se o campo esta vazio d erro valor = resultSet.getInt(i); } catch (SQLException e) { } properties.put(columnName, new Integer(valor)); break; case Types.REAL: properties.put(columnName, new Double(resultSet.getString(i))); break; case Types.SMALLINT: properties.put(columnName, new Short(resultSet.getShort(i))); break; case Types.TIME: properties.put(columnName, resultSet.getTime(i)); break; case Types.TIMESTAMP: properties.put(columnName, resultSet.getTimestamp(i)); break; // :FIXME: Throws java.lang.ClassCastException: java.lang.Integer // :FIXME: with Poolman and MySQL unless use getString. case Types.TINYINT: properties.put(columnName, new Byte(resultSet.getString(i))); break; case Types.CHAR: case Types.CLOB: case Types.VARCHAR: case Types.LONGVARCHAR: // :FIXME: Handle binaries differently? case Types.BLOB: case Types.LONGVARBINARY: case Types.VARBINARY: properties.put(columnName, resultSet.getString(i)); break; /* :FIXME: Add handlers for ARRAY BINARY BIT DISTINCT JAVA_OBJECT NULL NUMERIC OTHER REF STRUCT */ // Otherwise, pass as *String property to be converted default: properties.put(columnName + "String", resultSet.getString(i)); break; } // end switch }