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:konditer_reorganized_database.dao.CakeDao.java
@Override public int deleteCake(int cakeId) { String SQL_QUERY = "DELETE FROM cakes WHERE CAKE_ID = ? "; int rowCount = 0; rowCount = jdbcTemplate.update(SQL_QUERY, new Object[] { cakeId }, new int[] { Types.INTEGER }); Logger.getLogger(CakeDao.class.getName()).log(Level.SEVERE, " . {0} .", rowCount); /*/*from ww w.j a v a 2 s . com*/ if (rowCount > 0){ try { genIdDao.decrementCakeId(); } catch (SQLException ex) { Logger.getLogger(CakeDao.class.getName()).log(Level.SEVERE, null, ex); } } */ return rowCount; }
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;/* w w w.j a v a 2 s . c o m*/ 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:com.netspective.axiom.sql.QueryResultSet.java
public void fillReportFromMetaData(TabularReport report) throws SQLException { ResultSetMetaData rsmd = resultSet.getMetaData(); int numColumns = rsmd.getColumnCount(); TabularReportColumns columns = report.getColumns(); columns.clear();//from ww w .jav a2 s . c o m for (int c = 1; c <= numColumns; c++) { TabularReportColumn column = null; int dataType = rsmd.getColumnType(c); switch (dataType) { case Types.INTEGER: case Types.SMALLINT: case Types.BIGINT: case Types.TINYINT: case Types.BIT: column = new NumericColumn(); break; case Types.FLOAT: case Types.REAL: column = new DecimalColumn(); break; case Types.NUMERIC: case Types.DECIMAL: if (rsmd.getScale(c) > 0) column = new DecimalColumn(); else column = new NumericColumn(); break; default: column = new GeneralColumn(); break; } column.setColIndex(c - 1); column.setHeading(new StaticValueSource( TextUtils.getInstance().sqlIdentifierToText(rsmd.getColumnLabel(c), true))); column.setDataType(dataType); column.setWidth(rsmd.getColumnDisplaySize(c)); columns.add(column); } report.finalizeContents(); }
From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmMySql.CFCrmMySqlAttachmentTable.java
public void createAttachment(CFCrmAuthorization Authorization, CFCrmAttachmentBuff Buff) { final String S_ProcName = "createAttachment"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }/*from w w w . j av a2 s . c o m*/ ResultSet resultSet = null; try { long TenantId = Buff.getRequiredTenantId(); long ContactId = Buff.getRequiredContactId(); String Description = Buff.getRequiredDescription(); Integer MimeTypeId = Buff.getOptionalMimeTypeId(); String Attachment = Buff.getRequiredAttachment(); Connection cnx = schema.getCnx(); String sql = "call " + schema.getLowerDbSchemaName() + ".sp_create_attchmnt( ?, ?, ?, ?, ?, ?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + ", " + "?" + " )"; if (stmtCreateByPKey == null) { stmtCreateByPKey = cnx.prepareStatement(sql); } int argIdx = 1; stmtCreateByPKey.setLong(argIdx++, (Authorization == null) ? 0 : Authorization.getSecTenantId()); 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++, "ATTC"); stmtCreateByPKey.setLong(argIdx++, TenantId); 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); try { resultSet = stmtCreateByPKey.executeQuery(); } catch (SQLException e) { if (e.getErrorCode() != 1329) { throw e; } resultSet = null; } if ((resultSet != null) && resultSet.next()) { CFCrmAttachmentBuff createdBuff = unpackAttachmentResultSetToBuff(resultSet); if ((resultSet != null) && 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.setRequiredAttachmentId(createdBuff.getRequiredAttachmentId()); Buff.setRequiredContactId(createdBuff.getRequiredContactId()); Buff.setRequiredDescription(createdBuff.getRequiredDescription()); Buff.setOptionalMimeTypeId(createdBuff.getOptionalMimeTypeId()); Buff.setRequiredAttachment(createdBuff.getRequiredAttachment()); Buff.setRequiredRevision(createdBuff.getRequiredRevision()); Buff.setCreatedByUserId(createdBuff.getCreatedByUserId()); Buff.setCreatedAt(createdBuff.getCreatedAt()); Buff.setUpdatedByUserId(createdBuff.getUpdatedByUserId()); Buff.setUpdatedAt(createdBuff.getUpdatedAt()); } else { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected a single-record response, " + resultSet.getRow() + " rows selected"); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { } resultSet = null; } } }
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; }//w w w . j ava 2 s . c o 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:com.opencsv.ResultSetHelperService.java
private String getColumnValue(ResultSet rs, int colType, int colIndex, boolean trim, String dateFormatString, String timestampFormatString) throws SQLException, IOException { String value = ""; switch (colType) { case Types.BIT: case Types.JAVA_OBJECT: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getObject(colIndex), ""); value = ObjectUtils.toString(rs.getObject(colIndex), ""); break;// w w w .j a va2 s .co m case Types.BOOLEAN: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getBoolean(colIndex)); value = ObjectUtils.toString(rs.getBoolean(colIndex)); break; case Types.NCLOB: // todo : use rs.getNClob case Types.CLOB: Clob c = rs.getClob(colIndex); if (c != null) { StrBuilder sb = new StrBuilder(); sb.readFrom(c.getCharacterStream()); value = sb.toString(); } break; case Types.BIGINT: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getLong(colIndex)); value = ObjectUtils.toString(rs.getLong(colIndex)); break; case Types.DECIMAL: case Types.REAL: case Types.NUMERIC: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getBigDecimal(colIndex), ""); value = ObjectUtils.toString(rs.getBigDecimal(colIndex), ""); break; case Types.DOUBLE: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getDouble(colIndex)); value = ObjectUtils.toString(rs.getDouble(colIndex)); break; case Types.FLOAT: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getFloat(colIndex)); value = ObjectUtils.toString(rs.getFloat(colIndex)); break; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getInt(colIndex)); value = ObjectUtils.toString(rs.getInt(colIndex)); break; case Types.DATE: java.sql.Date date = rs.getDate(colIndex); if (date != null) { SimpleDateFormat df = new SimpleDateFormat(dateFormatString); value = df.format(date); } break; case Types.TIME: // Once Java 7 is the minimum supported version. // value = Objects.toString(rs.getTime(colIndex), ""); value = ObjectUtils.toString(rs.getTime(colIndex), ""); break; case Types.TIMESTAMP: value = handleTimestamp(rs.getTimestamp(colIndex), timestampFormatString); break; case Types.NVARCHAR: // todo : use rs.getNString case Types.NCHAR: // todo : use rs.getNString case Types.LONGNVARCHAR: // todo : use rs.getNString case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: String columnValue = rs.getString(colIndex); if (trim && columnValue != null) { value = columnValue.trim(); } else { value = columnValue; } break; default: value = ""; } if (rs.wasNull() || value == null) { value = ""; } return value; }
From source file:net.sourceforge.msscodefactory.cfinternet.v2_1.CFInternetSybase.CFInternetSybaseClusterTable.java
public int nextSecFormIdGen(CFInternetAuthorization Authorization, CFInternetClusterPKey PKey) { final String S_ProcName = "nextSecFormIdGen"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); }//from www. ja v a2s.c o m Connection cnx = schema.getCnx(); long Id = PKey.getRequiredId(); CallableStatement stmtSelectNextSecFormIdGen = null; try { String sql = "{ call sp_next_secformidgen( ?" + ", " + "?" + " ) }"; stmtSelectNextSecFormIdGen = cnx.prepareCall(sql); int argIdx = 1; stmtSelectNextSecFormIdGen.registerOutParameter(argIdx++, java.sql.Types.INTEGER); stmtSelectNextSecFormIdGen.setLong(argIdx++, Id); stmtSelectNextSecFormIdGen.execute(); int nextId = stmtSelectNextSecFormIdGen.getInt(1); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (stmtSelectNextSecFormIdGen != null) { try { stmtSelectNextSecFormIdGen.close(); } catch (SQLException e) { } stmtSelectNextSecFormIdGen = null; } } }
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; }//from w ww.j a va2 s . 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:edu.harvard.i2b2.crc.dao.setfinder.QueryResultInstanceSpringDao.java
/** * Function used to update result instance description * /* w ww . j a v a2s .c o m*/ * @param resultInstanceId * @param description */ public void updateResultInstanceDescription(String resultInstanceId, String description) { String sql = "update " + getDbSchemaName() + "qt_query_result_instance set description = ? where result_instance_id = ?"; jdbcTemplate.update(sql, new Object[] { description, Integer.parseInt(resultInstanceId) }, new int[] { Types.VARCHAR, Types.INTEGER }); }
From source file:net.sf.farrago.namespace.sfdc.SfdcUdx.java
public static void query(String query, String types, PreparedStatement resultInserter) throws SQLException { SoapBindingStub binding = (SoapBindingStub) FarragoUdrRuntime.getDataServerRuntimeSupport(null); try {/*from ww w .j a v a 2 s .co m*/ QueryOptions qo = new QueryOptions(); int batchsize = 500; qo.setBatchSize(new Integer(batchsize)); binding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(), "QueryOptions", qo); String objName = query; int fromIdx = query.lastIndexOf(" from"); if (fromIdx > 0) { objName = query.substring(fromIdx + 6); } // strip off quotes for boolean values query = stripQuotes(query, objName); log.info("SFDC Query: " + query); QueryResult qr = binding.query(query); if (qr.isDone()) { if (qr.getRecords() != null) { log.info(SfdcResource.instance().RetrievedAllRecordsMsg .str(Integer.toString(qr.getRecords().length), objName)); } } else { if (qr.getRecords() != null) { log.info(SfdcResource.instance().RetrievingRecordsMsg .str(Integer.toString(qr.getRecords().length), objName)); } } SObject[] records = qr.getRecords(); String[] metadataType = types.split(","); // query is of following format: // "select col1,col2,... from" String cols = query.substring(7); fromIdx = cols.lastIndexOf(" from"); cols = cols.substring(0, fromIdx); cols = cols.trim(); String[] columnValues = new String[metadataType.length]; if (records != null) { boolean bContinue = true; while (bContinue) { // for each record returned in query, // get value of each field for (int i = 0; i < records.length; i++) { MessageElement[] elements = records[i].get_any(); if (elements != null) { for (int j = 0; j < elements.length; j++) { MessageElement elt = elements[j]; String eltVal = elt.getValue(); columnValues[j] = (eltVal != null) ? eltVal : "null"; if (metadataType[j].indexOf("TIMESTAMP") != -1) { // TIMESTAMP if (eltVal != null) { String tstampstr = eltVal.replace("T", " "); tstampstr = tstampstr.substring(0, tstampstr.indexOf(".")); java.sql.Timestamp tstamp = java.sql.Timestamp.valueOf(tstampstr); resultInserter.setTimestamp(j + 1, tstamp); } else { resultInserter.setNull(j + 1, java.sql.Types.TIMESTAMP); } } else if (metadataType[j].indexOf("TIME") != -1) { // TIME if (eltVal != null) { String timestr = eltVal.substring(0, eltVal.indexOf(".")); java.sql.Time time = java.sql.Time.valueOf(timestr); resultInserter.setTime(j + 1, time); } else { resultInserter.setNull(j + 1, java.sql.Types.TIME); } } else if (metadataType[j].indexOf("DATE") != -1) { // DATE if (eltVal != null) { java.sql.Date dt = java.sql.Date.valueOf(eltVal); resultInserter.setDate(j + 1, dt); } else { resultInserter.setNull(j + 1, java.sql.Types.DATE); } } else if (metadataType[j].indexOf("INTEGER") != -1) { // INTEGER if (eltVal != null) { int iValue = 0; iValue = Integer.parseInt(eltVal); resultInserter.setInt(j + 1, iValue); } else { resultInserter.setNull(j + 1, java.sql.Types.INTEGER); } } else if (metadataType[j].indexOf("DOUBLE") != -1) { // DOUBLE if (eltVal != null) { resultInserter.setDouble(j + 1, Double.parseDouble(eltVal)); } else { resultInserter.setNull(j + 1, java.sql.Types.DOUBLE); } } else if (eltVal != null) { // VARCHAR - default int rightParen = metadataType[j].indexOf(")"); int prec = Integer.parseInt(metadataType[j].substring(8, rightParen)); if (eltVal.length() > prec) { eltVal = eltVal.substring(0, prec); columnValues[j] = eltVal; } resultInserter.setString(j + 1, eltVal); } else { resultInserter.setNull(j + 1, java.sql.Types.VARCHAR); } } resultInserter.executeUpdate(); } } if (qr.isDone()) { bContinue = false; } else { boolean relogin = true; int retryCnt = 0; while (relogin) { try { qr = binding.queryMore(qr.getQueryLocator()); relogin = false; } catch (AxisFault a) { if (a.getFaultString().contains("Invalid Session ID") && (retryCnt < RETRY_CNT)) { relogin = true; retryCnt++; binding = (SoapBindingStub) FarragoUdrRuntime .getDataServerRuntimeSupport(binding); } else { throw a; } } } records = qr.getRecords(); if (qr.isDone()) { if (qr.getRecords() != null) { log.info(SfdcResource.instance().RetrievedAllRecordsMsg .str(Integer.toString(qr.getRecords().length), objName)); } } else { if (qr.getRecords() != null) { log.info(SfdcResource.instance().RetrievingRecordsMsg .str(Integer.toString(qr.getRecords().length), objName)); } } } } } } catch (AxisFault ae) { SQLException retryExcn = new SQLException(ae.getFaultString(), null, 460150); Exception chainedEx = FarragoResource.instance().RetryableFailure.ex(retryExcn); throw SfdcResource.instance().BindingCallException.ex(ae.getFaultString(), chainedEx); } catch (RemoteException re) { SQLException retryExcn = new SQLException(re.getMessage(), null, 460150); Exception chainedEx = FarragoResource.instance().RetryableFailure.ex(retryExcn); throw SfdcResource.instance().BindingCallException.ex(re.getMessage(), chainedEx); } }