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.alibaba.otter.node.etl.common.db.DbPerfIntergration.java
@Test public void test_stack() { DbMediaSource dbMediaSource = new DbMediaSource(); dbMediaSource.setId(1L);//from ww w .ja va2 s .c o m dbMediaSource.setDriver("com.mysql.jdbc.Driver"); dbMediaSource.setUsername("otter"); dbMediaSource.setPassword("otter"); dbMediaSource.setUrl("jdbc:mysql://127.0.0.1:3306/retl"); dbMediaSource.setEncode("UTF-8"); dbMediaSource.setType(DataMediaType.MYSQL); DbDataMedia dataMedia = new DbDataMedia(); dataMedia.setSource(dbMediaSource); dataMedia.setId(1L); dataMedia.setName("ljhtable1"); dataMedia.setNamespace("otter"); final DbDialect dbDialect = dbDialectFactory.getDbDialect(2L, dataMedia.getSource()); want.object(dbDialect).clazIs(MysqlDialect.class); final TransactionTemplate transactionTemplate = dbDialect.getTransactionTemplate(); // ?? int minute = 5; int nextId = 1; final int thread = 10; final int batch = 50; final String sql = "insert into otter.ljhtable1 values(? , ? , ? , ?)"; final CountDownLatch latch = new CountDownLatch(thread); ExecutorService executor = new ThreadPoolExecutor(thread, thread, 60, TimeUnit.SECONDS, new ArrayBlockingQueue(thread * 2), new NamedThreadFactory("load"), new ThreadPoolExecutor.CallerRunsPolicy()); for (int sec = 0; sec < minute * 60; sec++) { // long startTime = System.currentTimeMillis(); for (int i = 0; i < thread; i++) { final int start = nextId + i * batch; executor.submit(new Runnable() { public void run() { try { transactionTemplate.execute(new TransactionCallback() { public Object doInTransaction(TransactionStatus status) { JdbcTemplate jdbcTemplate = dbDialect.getJdbcTemplate(); return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int idx) throws SQLException { int id = start + idx; StatementCreatorUtils.setParameterValue(ps, 1, Types.INTEGER, null, id); StatementCreatorUtils.setParameterValue(ps, 2, Types.VARCHAR, null, RandomStringUtils.randomAlphabetic(1000)); // RandomStringUtils.randomAlphabetic() long time = new Date().getTime(); StatementCreatorUtils.setParameterValue(ps, 3, Types.TIMESTAMP, new Timestamp(time)); StatementCreatorUtils.setParameterValue(ps, 4, Types.TIMESTAMP, new Timestamp(time)); } public int getBatchSize() { return batch; } }); } }); } finally { latch.countDown(); } } }); } long endTime = System.currentTimeMillis(); try { latch.await(1000 * 60L - (endTime - startTime), TimeUnit.MILLISECONDS); } catch (InterruptedException e) { e.printStackTrace(); } if (latch.getCount() != 0) { System.out.println("perf is not enough!"); System.exit(-1); } endTime = System.currentTimeMillis(); System.out.println("Time cost : " + (System.currentTimeMillis() - startTime)); try { TimeUnit.MILLISECONDS.sleep(1000L - (endTime - startTime)); } catch (InterruptedException e) { e.printStackTrace(); } nextId = nextId + thread * batch; } executor.shutdown(); }
From source file:co.nubetech.apache.hadoop.DataDrivenDBInputFormat.java
/** * @return the DBSplitter implementation to use to divide the table/query * into InputSplits.//from w w w .j a v a 2 s .co m */ protected DBSplitter getSplitter(int sqlDataType) { switch (sqlDataType) { case Types.NUMERIC: case Types.DECIMAL: return new BigDecimalSplitter(); case Types.BIT: case Types.BOOLEAN: return new BooleanSplitter(); case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: case Types.BIGINT: return new IntegerSplitter(); case Types.REAL: case Types.FLOAT: case Types.DOUBLE: return new FloatSplitter(); case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: return new TextSplitter(); case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return new DateSplitter(); default: // TODO: Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB, // BLOB, ARRAY // STRUCT, REF, DATALINK, and JAVA_OBJECT. return null; } }
From source file:konditer.client.dao.CustomerDao.java
@Override public void addCustomer(int customerId, String customerFirstName, String customerDopInfo) { String SQL_QUERY = "INSERT INTO customers ( CUSTOMER_ID, " + "DISCOUNT_ID, " + "CUSTOMER_LAST_NAME, " + "CUSTOMER_FIRST_NAME, " + "CUSTOMER_PARENT_NAME, " + "CUSTOMER_DATE_BORN, " + "CUSTOMER_INFO ) " + "VALUES (?,?,?,?,?,?,?)"; int rowCount = 0; try {//w ww .j a va2s . co m rowCount = jdbcTemplate.update(SQL_QUERY, new Object[] { customerId, 1, "", customerFirstName, "", new Date(), customerDopInfo }, new int[] { Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.VARCHAR }); Logger.getLogger(CustomerDao.class.getName()).log(Level.SEVERE, " : {0} .", rowCount + "\n" + customerDao.getCustomer(customerId).toString()); } catch (DataAccessException e) { rowCount = 0; Logger.getLogger(CustomerDao.class.getName()).log(Level.SEVERE, " . ?: {0} .", rowCount); } }
From source file:madgik.exareme.master.queryProcessor.analyzer.stat.Stat.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;/* w ww .j a v a 2 s . co m*/ } else if (columnType == Types.VARCHAR) { String query0 = "select max(length(`" + columnName + "`)) as length from (select `" + columnName + "` from `" + table_sample + "`)" + " where `" + columnName + "` is not null limit " + MAX_STRING_SAMPLE; 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:co.nubetech.hiho.mapreduce.lib.db.apache.DataDrivenDBInputFormat.java
/** * @return the DBSplitter implementation to use to divide the table/query into InputSplits. *///from ww w .j a v a2s . c o m protected DBSplitter getSplitter(int sqlDataType) { switch (sqlDataType) { case Types.NUMERIC: case Types.DECIMAL: return new BigDecimalSplitter(); case Types.BIT: case Types.BOOLEAN: return new BooleanSplitter(); case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: case Types.BIGINT: return new IntegerSplitter(); case Types.REAL: case Types.FLOAT: case Types.DOUBLE: return new FloatSplitter(); case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: return new TextSplitter(); case Types.DATE: case Types.TIME: case Types.TIMESTAMP: return new DateSplitter(); default: // TODO: Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT, CLOB, BLOB, ARRAY // STRUCT, REF, DATALINK, and JAVA_OBJECT. return null; } }
From source file:com.nabla.dc.server.ImportErrorManager.java
/** * Add error/*from w w w .j a v a 2s .c o m*/ * @param position - row number * @param fieldName - field name * @param error - error message * @throws SQLException */ @Override public void add(@Nullable final Integer position, @Nullable String fieldName, String error) throws DispatchException { if (isFull()) throw new FullErrorListException(); if (fieldName != null && fieldName.length() > MAX_FIELD_NAME) fieldName = fieldName.substring(0, MAX_FIELD_NAME); if (error == null || error.isEmpty()) error = CommonServerErrors.INTERNAL_ERROR.toString(); if (error.length() > MAX_ERROR_MESSAGE) error = error.substring(0, MAX_ERROR_MESSAGE); if (log.isTraceEnabled()) log.trace("[" + position + "] " + fieldName + ":" + error); try { if (stmt == null) { Database.executeUpdate(conn, "DELETE FROM import_error WHERE import_data_id=?;", batchId); stmt = conn.prepareStatement( "INSERT INTO import_error(import_data_id,line_no,field,error) VALUES(?,?,?,?);"); stmt.setInt(COL_ID, batchId); } if (position == null) stmt.setNull(COL_LINE_NO, Types.INTEGER); else stmt.setInt(COL_LINE_NO, position); if (fieldName == null) stmt.setNull(COL_FIELD, Types.VARCHAR); else stmt.setString(COL_FIELD, fieldName); ++size; stmt.setString(COL_ERROR, (size < maxErrors) ? error : ServerErrors.TOO_MANY_ERRORS.toString()); stmt.executeUpdate(); } catch (SQLException e) { if (log.isErrorEnabled()) log.error("failed to save import error to database", e); size = maxErrors; throw new FullErrorListException(); } }
From source file:com.bt.aloha.dao.StateInfoDaoImpl.java
public void add(StateInfoBase<T> info, String collectionTypeName) { if (collectionTypeName == null) throw new IllegalArgumentException("Cannot add null collection type to collection."); if (info == null) throw new IllegalArgumentException("Cannot add null info object to collection."); if (info.getId() == null) throw new IllegalArgumentException("Cannot add info object with null id to collection."); try {/*w ww. j a v a 2 s.c o m*/ Object[] params = new Object[] { info.getId(), collectionTypeName, info.getVersionId(), info.getLastUsedTime(), info.isDead() ? 1 : 0, new SqlLobValue(new ObjectSerialiser().serialise(info)), }; int[] types = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BIGINT, Types.INTEGER, Types.BLOB }; getJdbcTemplate().update(INSERT_SQL, params, types); } catch (DataIntegrityViolationException e) { throw new IllegalArgumentException( String.format("Info %s already exists in database, use replaceDialog instead", info.getId()), e); } catch (DataAccessException e) { throw new IllegalArgumentException(String.format("Cannot add info %s to database", info.getId()), e); } }
From source file:com.cisco.dvbu.ps.utils.log.GetServerMetadataLog.java
/** * Called during introspection to get the description of the input and * output parameters. Should not return null. *//* w w w. j ava 2 s. c om*/ public ParameterInfo[] getParameterInfo() { return new ParameterInfo[] { new ParameterInfo("result", TYPED_CURSOR, DIRECTION_OUT, new ParameterInfo[] { new ParameterInfo("change_time", Types.TIMESTAMP, DIRECTION_NONE), new ParameterInfo("cid", Types.INTEGER, DIRECTION_NONE), new ParameterInfo("domain", Types.VARCHAR, DIRECTION_NONE), new ParameterInfo("user", Types.VARCHAR, DIRECTION_NONE), new ParameterInfo("userid", Types.INTEGER, DIRECTION_NONE), new ParameterInfo("hostname", Types.VARCHAR, DIRECTION_NONE), new ParameterInfo("operation", Types.VARCHAR, DIRECTION_NONE), new ParameterInfo("resource_id", Types.INTEGER, DIRECTION_NONE), new ParameterInfo("resource_path", Types.VARCHAR, DIRECTION_NONE), new ParameterInfo("resource_type", Types.VARCHAR, DIRECTION_NONE), new ParameterInfo("message", Types.VARCHAR, DIRECTION_NONE) }) }; }
From source file:com.streamsets.pipeline.stage.it.MultiplexingIT.java
@Test public void testMultiplexing() throws Exception { HiveMetadataProcessor processor = new HiveMetadataProcessorBuilder().table("${record:attribute('table')}") .partitions(new PartitionConfigBuilder() .addPartition("country", HiveType.STRING, "${record:attribute('country')}") .addPartition("year", HiveType.STRING, "${record:attribute('year')}").build()) .build();/*ww w. ja va2 s.c o m*/ HiveMetastoreTarget hiveTarget = new HiveMetastoreTargetBuilder().build(); // We build stream that have two tables List<Record> records = new LinkedList<>(); Map<String, Field> map = new LinkedHashMap<>(); map.put("id", Field.create(Field.Type.INTEGER, 1)); map.put("name", Field.create(Field.Type.STRING, "San Francisco")); Record record = RecordCreator.create("s", "s:1"); record.set(Field.create(map)); record.getHeader().setAttribute("table", "towns"); record.getHeader().setAttribute("country", "US"); record.getHeader().setAttribute("year", "2016"); records.add(record); map = new LinkedHashMap<>(); map.put("id", Field.create(Field.Type.INTEGER, 1)); map.put("customer", Field.create(Field.Type.STRING, "Santhosh")); map.put("value", Field.create(Field.Type.INTEGER, 200)); record = RecordCreator.create("s", "s:1"); record.set(Field.create(map)); record.getHeader().setAttribute("table", "invoice"); record.getHeader().setAttribute("country", "India"); record.getHeader().setAttribute("year", "2015"); records.add(record); map = new LinkedHashMap<>(); map.put("id", Field.create(Field.Type.INTEGER, 2)); map.put("name", Field.create(Field.Type.STRING, "Brno")); record = RecordCreator.create("s", "s:1"); record.set(Field.create(map)); record.getHeader().setAttribute("table", "towns"); record.getHeader().setAttribute("country", "CR"); record.getHeader().setAttribute("year", "2016"); records.add(record); map = new LinkedHashMap<>(); map.put("id", Field.create(Field.Type.INTEGER, 2)); map.put("customer", Field.create(Field.Type.STRING, "Junko")); map.put("value", Field.create(Field.Type.INTEGER, 300)); record = RecordCreator.create("s", "s:1"); record.set(Field.create(map)); record.getHeader().setAttribute("table", "invoice"); record.getHeader().setAttribute("country", "Japan"); record.getHeader().setAttribute("year", "2015"); records.add(record); processRecords(processor, hiveTarget, records); assertTableExists("default.towns"); assertTableExists("default.invoice"); assertQueryResult("select * from towns order by id", new QueryValidator() { @Override public void validateResultSet(ResultSet rs) throws Exception { assertResultSetStructure(rs, new ImmutablePair("towns.id", Types.INTEGER), new ImmutablePair("towns.name", Types.VARCHAR), new ImmutablePair("towns.country", Types.VARCHAR), new ImmutablePair("towns.year", Types.VARCHAR)); Assert.assertTrue("Unexpected number of rows", rs.next()); Assert.assertEquals(1, rs.getLong(1)); Assert.assertEquals("San Francisco", rs.getString(2)); Assert.assertEquals("US", rs.getString(3)); Assert.assertEquals("2016", rs.getString(4)); Assert.assertTrue("Unexpected number of rows", rs.next()); Assert.assertEquals(2, rs.getLong(1)); Assert.assertEquals("Brno", rs.getString(2)); Assert.assertEquals("CR", rs.getString(3)); Assert.assertEquals("2016", rs.getString(4)); Assert.assertFalse("Unexpected number of rows", rs.next()); } }); assertQueryResult("select * from invoice order by id", new QueryValidator() { @Override public void validateResultSet(ResultSet rs) throws Exception { assertResultSetStructure(rs, new ImmutablePair("invoice.id", Types.INTEGER), new ImmutablePair("invoice.customer", Types.VARCHAR), new ImmutablePair("invoice.value", Types.INTEGER), new ImmutablePair("invoice.country", Types.VARCHAR), new ImmutablePair("invoice.year", Types.VARCHAR)); Assert.assertTrue("Unexpected number of rows", rs.next()); Assert.assertEquals(1, rs.getLong(1)); Assert.assertEquals("Santhosh", rs.getString(2)); Assert.assertEquals(200, rs.getLong(3)); Assert.assertEquals("India", rs.getString(4)); Assert.assertEquals("2015", rs.getString(5)); Assert.assertTrue("Unexpected number of rows", rs.next()); Assert.assertEquals(2, rs.getLong(1)); Assert.assertEquals("Junko", rs.getString(2)); Assert.assertEquals(300, rs.getLong(3)); Assert.assertEquals("Japan", rs.getString(4)); Assert.assertEquals("2015", rs.getString(5)); Assert.assertFalse("Unexpected number of rows", rs.next()); } }); }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseTenantTable.java
public int nextTSecGroupIdGen(CFAstAuthorization Authorization, CFAstTenantPKey PKey) { final String S_ProcName = "nextTSecGroupIdGen"; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Not in a transaction"); }//from w w w . jav a 2 s . co m Connection cnx = schema.getCnx(); long Id = PKey.getRequiredId(); CallableStatement stmtSelectNextTSecGroupIdGen = null; try { String sql = "{ call sp_next_tsecgroupidgen( ?" + ", " + "?" + " ) }"; stmtSelectNextTSecGroupIdGen = cnx.prepareCall(sql); int argIdx = 1; stmtSelectNextTSecGroupIdGen.registerOutParameter(argIdx++, java.sql.Types.INTEGER); stmtSelectNextTSecGroupIdGen.setLong(argIdx++, Id); stmtSelectNextTSecGroupIdGen.execute(); int nextId = stmtSelectNextTSecGroupIdGen.getInt(1); return (nextId); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } finally { if (stmtSelectNextTSecGroupIdGen != null) { try { stmtSelectNextTSecGroupIdGen.close(); } catch (SQLException e) { } stmtSelectNextTSecGroupIdGen = null; } } }