List of usage examples for java.sql Types BIGINT
int BIGINT
To view the source code for java.sql Types BIGINT.
Click Source Link
The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BIGINT
.
From source file:com.squid.core.jdbc.formatter.DefaultJDBCDataFormatter.java
public String formatJDBCObject(final Object jdbcObject, final int colType) throws SQLException { String value = ""; switch (colType) { case Types.BIT: if (jdbcObject != null) { value = String.valueOf(jdbcObject); }//from w w w .j a v a 2 s . c o m break; case Types.BOOLEAN: if (jdbcObject != null) { value = new Boolean(jdbcObject.toString()).toString(); } break; case Types.BIGINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: case Types.NUMERIC: if (jdbcObject != null) { value = "" + formatter.formatDecimal(jdbcObject); } break; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: if (jdbcObject != null) { value = "" + formatter.formatDecimal(jdbcObject); } break; case Types.CLOB: if (jdbcObject != null) { try { value = read((Clob) jdbcObject); } catch (SQLException sqle) { value = ""; } catch (IOException ioe) { value = ""; } } break; case Types.ARRAY: try { ResultSet rs = ((Array) jdbcObject).getResultSet(); int arrayType = ((Array) jdbcObject).getBaseType(); boolean isNotNew = false; while (rs.next()) { String current = formatJDBCObject(rs.getObject(2), arrayType); if ("".equals(current.trim()) == false) { if (isNotNew) { value = value + ","; } else { isNotNew = !isNotNew; } value = value + current; } } if ("".equals(value) == false) { value = "{" + value + "}"; } } catch (SQLException sqle) { value = ""; } break; case Types.JAVA_OBJECT: if (jdbcObject != null) { value = String.valueOf(jdbcObject); } break; case Types.DATE: if (jdbcObject != null) { value = formatter.formatDate(jdbcObject); } break; case Types.TIME: if (jdbcObject != null) { value = ((Time) jdbcObject).toString(); } break; case Types.TIMESTAMP: if (jdbcObject != null) { value = formatter.formatTimestamp(jdbcObject); } break; case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: if (jdbcObject != null) { value = jdbcObject.toString(); } else { value = "NULL"; } break; case Types.BINARY: value = new String((byte[]) jdbcObject); break; default: value = ""; } if (value == null) { value = ""; } return value; }
From source file:ResultsDecoratorSQL.java
public void write(ResultSet rs) throws IOException, SQLException { ResultSetMetaData md = rs.getMetaData(); // This assumes you're not using a Join!! String tableName = md.getTableName(1); int cols = md.getColumnCount(); StringBuffer sb = new StringBuffer("insert into ").append(tableName).append("("); for (int i = 1; i <= cols; i++) { sb.append(md.getColumnName(i));//from w w w.j a va 2 s.c o m if (i != cols) { sb.append(", "); } } sb.append(") values ("); String insertCommand = sb.toString(); while (rs.next()) { println(insertCommand); for (int i = 1; i <= cols; i++) { String tmp = rs.getString(i); if (rs.wasNull()) { print("null"); } else { int type = md.getColumnType(i); // Don't quote numeric types; quote all others for now. switch (type) { case Types.BIGINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.INTEGER: print(tmp); break; default: tmp = tmp.replaceAll("'", "''"); print("'" + tmp + "'"); } } if (i != cols) { print(", "); } } println(");"); } }
From source file:au.com.ish.derbydump.derbydump.metadata.Column.java
/** * Get a string value for the value in this column in the datarow * /* w w w. j a va2 s . co m*/ * @param dataRow The row which we are exporting * @return an SQL statement compliant string version of the value */ public String toString(ResultSet dataRow) throws SQLException { switch (getColumnDataType()) { case Types.BINARY: case Types.VARBINARY: case Types.BLOB: { Blob obj = dataRow.getBlob(columnName); return (obj == null) ? "NULL" : processBinaryData(obj); } case Types.CLOB: { Clob obj = dataRow.getClob(columnName); return (obj == null) ? "NULL" : processClobData(obj); } case Types.CHAR: case Types.LONGNVARCHAR: case Types.VARCHAR: { String obj = dataRow.getString(columnName); return (obj == null) ? "NULL" : processStringData(obj); } case Types.TIME: { Time obj = dataRow.getTime(columnName); return (obj == null) ? "NULL" : processStringData(obj.toString()); } case Types.DATE: { Date obj = dataRow.getDate(columnName); return (obj == null) ? "NULL" : processStringData(obj.toString()); } case Types.TIMESTAMP: { Timestamp obj = dataRow.getTimestamp(columnName); return (obj == null) ? "NULL" : processStringData(obj.toString()); } case Types.SMALLINT: { Object obj = dataRow.getObject(columnName); return (obj == null) ? "NULL" : obj.toString(); } case Types.BIGINT: { Object obj = dataRow.getObject(columnName); return (obj == null) ? "NULL" : obj.toString(); } case Types.INTEGER: { Object obj = dataRow.getObject(columnName); return (obj == null) ? "NULL" : obj.toString(); } case Types.NUMERIC: case Types.DECIMAL: { BigDecimal obj = dataRow.getBigDecimal(columnName); return (obj == null) ? "NULL" : String.valueOf(obj); } case Types.REAL: case Types.FLOAT: { Float obj = dataRow.getFloat(columnName); // dataRow.getFloat() always returns a value. only way to check the null is wasNull() method return (dataRow.wasNull()) ? "NULL" : String.valueOf(obj); } case Types.DOUBLE: { Double obj = dataRow.getDouble(columnName); return (dataRow.wasNull()) ? "NULL" : String.valueOf(obj); } default: { Object obj = dataRow.getObject(columnName); return (obj == null) ? "NULL" : obj.toString(); } } }
From source file:annis.sqlgen.AnnotatedSpanExtractor.java
@Override public AnnotatedSpan mapRow(ResultSet resultSet, int rowNum) throws SQLException { long id = resultSet.getLong("id"); String coveredText = resultSet.getString("span"); Array arrayAnnotation = resultSet.getArray("annotations"); ResultSetMetaData rsMeta = resultSet.getMetaData(); Array arrayMeta = null;//from ww w .jav a2 s .c o m for (int i = 1; i <= rsMeta.getColumnCount(); i++) { if ("metadata".equals(rsMeta.getColumnName(i))) { arrayMeta = resultSet.getArray(i); break; } } List<Annotation> annotations = extractAnnotations(arrayAnnotation); List<Annotation> metaData = arrayMeta == null ? new LinkedList<Annotation>() : extractAnnotations(arrayMeta); // create key Array sqlKey = resultSet.getArray("key"); Validate.isTrue(!resultSet.wasNull(), "Match group identifier must not be null"); Validate.isTrue(sqlKey.getBaseType() == Types.BIGINT, "Key in database must be from the type \"bigint\" but was \"" + sqlKey.getBaseTypeName() + "\""); List<Long> key = Arrays.asList((Long[]) sqlKey.getArray()); return new AnnotatedSpan(id, coveredText, annotations, metaData, key); }
From source file:com.hangum.tadpole.engine.sql.util.RDBTypeToJavaTypeUtils.java
/** * ? ?// w w w. j a v a 2 s . c o m * * @param sqlType * @return */ public static boolean isNumberType(int sqlType) { switch (sqlType) { case Types.BIGINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.INTEGER: case Types.NUMERIC: case Types.BIT: case Types.SMALLINT: case Types.TINYINT: return true; } return false; }
From source file:com.hmsinc.epicenter.tools.reclassifier.Reclassifier.java
@Transactional public void run() { setup();//from w w w . j a v a2 s .c om final String destinationTable = (arguments.length > 4) ? arguments[4] : DEFAULT_TABLE_NAME; final String query = new StringBuilder("INSERT INTO ").append(destinationTable) .append(INSERT_CLASSIFICATION).toString(); final BatchSqlUpdate updater = new BatchSqlUpdate(modelDataSource, query); updater.declareParameter(new SqlParameter(Types.BIGINT)); updater.declareParameter(new SqlParameter(Types.BIGINT)); updater.setBatchSize(BATCH_SIZE); updater.compile(); final StatelessSession ss = ((Session) entityManager.getDelegate()).getSessionFactory() .openStatelessSession(); final Criteria c = ss.createCriteria(target.getInteractionClass()) .add(Restrictions.eq("patientClass", target.getPatientClass())).addOrder(Order.asc("id")) .setCacheable(false); if (arguments.length > 2) { c.add(Restrictions.gt("id", Long.valueOf(arguments[2]))); } if (arguments.length > 3) { c.add(Restrictions.lt("id", Long.valueOf(arguments[3]))); } final ScrollableResults sr = c.scroll(ScrollMode.FORWARD_ONLY); int i = 0; while (sr.next()) { final Interaction interaction = (Interaction) sr.get(0); final Set<Classification> classifications = classificationService.classify(interaction, target); save(interaction, classifications, updater); i++; if (i % BATCH_SIZE == 0) { logger.info("Processed {} interactions (current id: {})", i, interaction.getId()); } ((Session) entityManager.getDelegate()).evict(interaction); } sr.close(); updater.flush(); }
From source file:annis.sqlgen.MatrixSqlGenerator.java
@Override public List<AnnotatedMatch> extractData(ResultSet resultSet) throws SQLException, DataAccessException { List<AnnotatedMatch> matches = new ArrayList<AnnotatedMatch>(); Map<List<Long>, AnnotatedSpan[]> matchesByGroup = new HashMap<List<Long>, AnnotatedSpan[]>(); while (resultSet.next()) { long id = resultSet.getLong("id"); String coveredText = resultSet.getString("span"); Array arrayAnnotation = resultSet.getArray("annotations"); Array arrayMeta = resultSet.getArray("metadata"); List<Annotation> annotations = extractAnnotations(arrayAnnotation); List<Annotation> metaData = extractAnnotations(arrayMeta); // create key Array sqlKey = resultSet.getArray("key"); Validate.isTrue(!resultSet.wasNull(), "Match group identifier must not be null"); Validate.isTrue(sqlKey.getBaseType() == Types.BIGINT, "Key in database must be from the type \"bigint\" but was \"" + sqlKey.getBaseTypeName() + "\""); Long[] keyArray = (Long[]) sqlKey.getArray(); int matchWidth = keyArray.length; List<Long> key = Arrays.asList(keyArray); if (!matchesByGroup.containsKey(key)) { matchesByGroup.put(key, new AnnotatedSpan[matchWidth]); }//from w w w . j a v a 2s .c o m // set annotation spans for *all* positions of the id // (node could have matched several times) for (int posInMatch = 0; posInMatch < key.size(); posInMatch++) { if (key.get(posInMatch) == id) { matchesByGroup.get(key)[posInMatch] = new AnnotatedSpan(id, coveredText, annotations, metaData); } } } for (AnnotatedSpan[] match : matchesByGroup.values()) { matches.add(new AnnotatedMatch(Arrays.asList(match))); } return matches; }
From source file:com.vecna.dbDiff.builder.RelationalDatabaseBuilderTest.java
/** * Test {@link RelationalDatabaseBuilderImpl#createRelationalDatabase(CatalogSchema)). * @throws Exception/*from w ww . j a va 2s .c om*/ */ public void testCreateRelationalDatabase() throws Exception { RelationalDatabase database = getDatabase(); assertEquals("wrong number of tables", 2, database.getTables().size()); RelationalTable personTable = database.getTableByName("PERSON"); assertNotNull("table PERSON not found", personTable); List<Column> cols = new ArrayList<>(personTable.getColumns()); assertEquals("wrong number of columns", 3, cols.size()); assertEquals("wrong column", "ID", cols.get(0).getName()); assertEquals("wrong column", Boolean.FALSE, cols.get(0).getIsNullable()); assertEquals("wrong column", Types.BIGINT, cols.get(0).getType()); assertEquals("wrong column", "NAME", cols.get(1).getName()); assertEquals("wrong column", Boolean.FALSE, cols.get(1).getIsNullable()); assertEquals("wrong column", Types.VARCHAR, cols.get(1).getType()); assertEquals("wrong column", "DOB", cols.get(2).getName()); assertEquals("wrong column", Boolean.FALSE, cols.get(2).getIsNullable()); assertEquals("wrong column", Types.TIMESTAMP, cols.get(2).getType()); assertEquals("wrong number PK columns", Arrays.asList("ID"), personTable.getPkColumns()); assertEquals("wrong number of indices", 2, personTable.getIndices().size()); RelationalIndex nameDOB = getIndex(personTable, "NAME", "DOB"); assertEquals("NAME_DOB_IDX", nameDOB.getName()); getIndex(personTable, "ID"); RelationalTable joinTable = database.getTableByName("PERSON_RELATIVES"); cols = new ArrayList<>(joinTable.getColumns()); assertEquals("wrong number of columns", 3, cols.size()); assertEquals("wrong column", "PERSON_ID", cols.get(0).getName()); assertEquals("wrong column", Boolean.FALSE, cols.get(0).getIsNullable()); assertEquals("wrong column", Types.BIGINT, cols.get(0).getType()); assertEquals("wrong column", "RELATIVE_ID", cols.get(1).getName()); assertEquals("wrong column", Boolean.FALSE, cols.get(1).getIsNullable()); assertEquals("wrong column", Types.BIGINT, cols.get(1).getType()); assertEquals("wrong column", "RELATIONSHIP", cols.get(2).getName()); assertEquals("wrong column", Boolean.TRUE, cols.get(2).getIsNullable()); assertEquals("wrong column", Types.VARCHAR, cols.get(2).getType()); assertEquals("wrong PK columns", Arrays.asList("PERSON_ID", "RELATIVE_ID"), joinTable.getPkColumns()); getIndex(joinTable, "PERSON_ID", "RELATIVE_ID"); ForeignKey fkPerson = getForeignKey(joinTable, "FK_PERSON"); assertEquals("PERSON_ID", fkPerson.getFkColumn()); assertEquals("PERSON_RELATIVES", fkPerson.getFkTable()); assertEquals("ID", fkPerson.getPkColumn()); assertEquals("PERSON", fkPerson.getPkTable()); ForeignKey fkRelative = getForeignKey(joinTable, "FK_RELATIVE"); assertEquals("RELATIVE_ID", fkRelative.getFkColumn()); assertEquals("PERSON_RELATIVES", fkRelative.getFkTable()); assertEquals("ID", fkRelative.getPkColumn()); assertEquals("PERSON", fkRelative.getPkTable()); }
From source file:db.migration.V055__UpdateECTS.java
private int getNextHibernateSequence(JdbcTemplate jdbcTemplate) { // Returns next global id List<Map> resultSet = jdbcTemplate.query("SELECT nextval('public.hibernate_sequence')", new RowMapper<Map>() { @Override/*from w w w . j a v a2 s . co m*/ public Map mapRow(ResultSet rs, int rowNum) throws SQLException { Map r = new HashMap<String, Object>(); ResultSetMetaData metadata = rs.getMetaData(); for (int i = 1; i <= metadata.getColumnCount(); i++) { String cname = metadata.getColumnName(i); int ctype = metadata.getColumnType(i); switch (ctype) { case Types.BIGINT: // id r.put(cname, rs.getInt(cname)); break; default: break; } } return r; } }); for (Map m : resultSet) { return (int) m.get("nextval"); } return 0; }
From source file:com.sangupta.fileanalysis.db.DBResultViewer.java
/** * View resutls of a {@link ResultSet}.// w w w.j a v a 2 s . co m * * @param resultSet * @throws SQLException */ public void viewResult(ResultSet resultSet) throws SQLException { if (resultSet == null) { // nothing to do return; } // collect the meta ResultSetMetaData meta = resultSet.getMetaData(); final int numColumns = meta.getColumnCount(); final int[] displaySizes = new int[numColumns + 1]; final int[] colType = new int[numColumns + 1]; for (int index = 1; index <= numColumns; index++) { colType[index] = meta.getColumnType(index); displaySizes[index] = getColumnSize(meta.getTableName(index), meta.getColumnName(index), colType[index]); } // display the header row for (int index = 1; index <= numColumns; index++) { center(meta.getColumnLabel(index), displaySizes[index]); } System.out.println("|"); for (int index = 1; index <= numColumns; index++) { System.out.print("+" + StringUtils.repeat('-', displaySizes[index] + 2)); } System.out.println("+"); // start iterating over the result set int rowsDisplayed = 0; int numRecords = 0; while (resultSet.next()) { // read and display the value rowsDisplayed++; numRecords++; for (int index = 1; index <= numColumns; index++) { switch (colType[index]) { case Types.DECIMAL: case Types.DOUBLE: case Types.REAL: format(resultSet.getDouble(index), displaySizes[index]); continue; case Types.INTEGER: case Types.SMALLINT: format(resultSet.getInt(index), displaySizes[index]); continue; case Types.VARCHAR: format(resultSet.getString(index), displaySizes[index], false); continue; case Types.TIMESTAMP: format(resultSet.getTimestamp(index), displaySizes[index]); continue; case Types.BIGINT: format(resultSet.getBigDecimal(index), displaySizes[index]); continue; } } // terminator for row and new line System.out.println("|"); // check for rows displayed if (rowsDisplayed == 20) { // ask the user if more data needs to be displayed String cont = ConsoleUtils.readLine("Type \"it\" for more: ", true); if (!"it".equalsIgnoreCase(cont)) { break; } // continue; rowsDisplayed = 0; continue; } } System.out.println("\nTotal number of records found: " + numRecords); }