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.streamsets.pipeline.stage.it.AvroToParquetHiveIT.java
@Parameterized.Parameters(name = "type({0})") public static Collection<Object[]> data() throws Exception { return Arrays.asList(new Object[][] { // Primitive types { "\"boolean\"", true, true, "BOOLEAN", Types.BOOLEAN, "0" }, { "\"int\"", Integer.MIN_VALUE, Integer.MIN_VALUE, "INT", Types.INTEGER, "0" }, { "\"long\"", Long.MAX_VALUE, Long.MAX_VALUE, "BIGINT", Types.BIGINT, "0" }, // From some reason type is FLOAT, but returned object is double { "\"float\"", Float.NaN, Double.NaN, "FLOAT", Types.FLOAT, "0" }, { "\"double\"", Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, "DOUBLE", Types.DOUBLE, "0" }, { "\"bytes\"", ByteBuffer.wrap(new byte[] { (byte) 0x00, (byte) 0xFF }), new byte[] { (byte) 0x00, (byte) 0xFF }, "BINARY", Types.BINARY, "1.0" }, { "\"string\"", new Utf8("StreamSets"), "StreamSets", "STRING", Types.VARCHAR, "1.0" }, // Complex types are skipped for now // Logical types { DECIMAL.toString(), ByteBuffer.wrap(new byte[] { (byte) 0x0F }), new BigDecimal("2"), "DECIMAL", Types.DECIMAL, "0" }, { DATE.toString(), 17039, new java.sql.Date(116, 7, 26), "DATE", Types.DATE, "1.2" }, }); }
From source file:com.nabla.wapp.server.json.SqlColumn.java
public void write(final ResultSet rs, int column, final JSONObject record) throws SQLException { switch (type) { case Types.BIGINT: case Types.INTEGER: case Types.SMALLINT: case Types.TINYINT: record.put(label, rs.getInt(column)); break;//from ww w. java2 s . c o m case Types.BOOLEAN: case Types.BIT: record.put(label, rs.getBoolean(column)); break; case Types.DATE: final Date dt = rs.getDate(column); if (rs.wasNull()) record.put(label, null); else record.put(label, new JSonDate(dt)); return; case Types.TIMESTAMP: final Timestamp tm = rs.getTimestamp(column); if (rs.wasNull()) record.put(label, null); else record.put(label, timeStampFormat.format(tm)); return; case Types.DOUBLE: record.put(label, rs.getDouble(column)); break; case Types.FLOAT: record.put(label, rs.getFloat(column)); break; case Types.NULL: record.put(label, null); return; default: record.put(label, rs.getString(column)); break; } if (rs.wasNull()) record.put(label, null); }
From source file:com.redsqirl.workflow.utils.jdbc.GenericConfFile.java
public GenericConfFile(String name, Connection conn) throws SQLException { dictionaryName = name;//from w ww. j a v a2 s. c o m databaseMetaData = conn.getMetaData(); typeRecognized = new LinkedHashMap<Integer, FieldType>(); typeRecognized.put(Types.BOOLEAN, FieldType.BOOLEAN); typeRecognized.put(Types.DATE, FieldType.DATETIME); typeRecognized.put(Types.TIME, FieldType.DATETIME); typeRecognized.put(Types.DOUBLE, FieldType.DOUBLE); typeRecognized.put(Types.NUMERIC, FieldType.DOUBLE); typeRecognized.put(Types.DECIMAL, FieldType.DOUBLE); typeRecognized.put(Types.REAL, FieldType.DOUBLE); typeRecognized.put(Types.FLOAT, FieldType.FLOAT); typeRecognized.put(Types.INTEGER, FieldType.INT); typeRecognized.put(Types.SMALLINT, FieldType.INT); typeRecognized.put(Types.TINYINT, FieldType.INT); typeRecognized.put(Types.BIGINT, FieldType.LONG); typeRecognized.put(Types.VARCHAR, FieldType.STRING); typeRecognized.put(Types.CHAR, FieldType.STRING); typeRecognized.put(Types.LONGVARCHAR, FieldType.STRING); typeRecognized.put(Types.NVARCHAR, FieldType.STRING); typeRecognized.put(Types.NCHAR, FieldType.STRING); typeRecognized.put(Types.LONGNVARCHAR, FieldType.STRING); typeRecognized.put(Types.TIMESTAMP, FieldType.TIMESTAMP); }
From source file:com.zousu.mongopresser.Presser.java
public void press() { //get a list of all the tables and columns logger.info("Starting MySQL to Mongo Conversion..."); logger.info("Preparing Tables..."); mySQLHandler.initialiseDatabase();//w w w.j a v a2 s . c o m List<Table> tables = mySQLHandler.getTableList(); for (int i = 0; i < tables.size(); i++) { Table table = tables.get(i); List<Column> columns = table.getColumns(); List<DBObject> dboList = new ArrayList<DBObject>(); SqlRowSet rs = mySQLHandler.selectAllFromTable(table.getTableName()); logger.info("Creating objects for " + table.getTableName() + "..."); while (rs.next()) { BasicDBObject dbo = new BasicDBObject(); for (int j = 0; j < columns.size(); j++) { Column col = columns.get(j); String colName = col.getColumnName(); switch (col.getType()) { case Types.INTEGER: case Types.BIGINT: dbo.append(colName, rs.getInt(colName)); break; case Types.DOUBLE: dbo.append(colName, rs.getDouble(colName)); break; case Types.DATE: dbo.append(colName, rs.getDate(colName)); break; default: dbo.append(colName, rs.getString(colName)); break; } } dboList.add(dbo); } //now insert it logger.info("Inserting " + dboList.size() + " mongo rows into " + table.getTableName() + "..."); table.setNumOfRows(dboList.size()); try { mongoHandler.createCollection(table.getTableName(), true); mongoHandler.batchInsert(dboList, table.getTableName()); assert (mongoHandler.getNumObjectsInCollection(table.getTableName()) == dboList.size()); logger.info(table.getTableName() + " DONE!"); } catch (CollectionExistException e) { e.printStackTrace(); } } logger.info(tables.size() + " collections added!"); //now check go get it from mongo and check if the data there is correct logger.info("Checking mongo consistency..."); for (int i = 0; i < tables.size(); i++) { Table table = tables.get(i); assert (mongoHandler.getNumObjectsInCollection(table.getTableName()) == table.getNumOfRows()); logger.info(table.getTableName() + " consistent!"); } logger.info("MySQL to Mongo Conversion Completed!!!!"); }
From source file:com.draagon.meta.manager.db.driver.MSSQLDriver.java
/** * Creates a table in the database/* ww w.j a v a2 s .c o m*/ */ @Override public void createTable(Connection c, TableDef table) throws SQLException { String query = "CREATE TABLE [" + table + "] (\n"; boolean multi = (table.getPrimaryKeys().size() > 1); boolean hasIdentity = false; // Create the individual table fields int found = 0; for (ColumnDef col : table.getColumns()) { String name = col.getName(); if (name == null || name.length() == 0) { throw new IllegalArgumentException("No name defined for column [" + col + "]"); } if (found > 0) query += ",\n"; found++; String flags = ""; if (col.isPrimaryKey() && !multi) flags = "PRIMARY KEY "; else if (col.isUnique()) flags = "UNIQUE "; //else if (getManager().isIndex(mf)) flags = "NONCLUSTERED "; switch (col.getSQLType()) { case Types.BOOLEAN: case Types.BIT: query += "[" + name + "] [bit] " + flags; break; case Types.TINYINT: query += "[" + name + "] [tinyint] " + flags; break; case Types.SMALLINT: query += "[" + name + "] [smallint] " + flags; break; case Types.INTEGER: query += "[" + name + "] [int] " + flags; break; case Types.BIGINT: query += "[" + name + "] [bigint] " + flags; break; case Types.FLOAT: query += "[" + name + "] [float] " + flags; break; case Types.DOUBLE: query += "[" + name + "] [decimal](19,4) " + flags; break; case Types.TIMESTAMP: query += "[" + name + "] [datetime] " + flags; break; case Types.VARCHAR: query += "[" + name + "] [varchar](" + col.getLength() + ") " + flags; break; default: throw new IllegalArgumentException("Table [" + table + "] with Column [" + col + "] is of SQL type (" + col.getSQLType() + ") which is not support by this database"); } // Create the identity columns if (col.isAutoIncrementor()) { if (hasIdentity) throw new MetaException( "Table [" + table + "] cannot have multiple identity (auto id) columns!"); query += "NOT NULL IDENTITY( " + col.getSequence().getStart() + ", " + col.getSequence().getIncrement() + " ) "; hasIdentity = true; } } query += "\n)"; // This means there were no columns defined for the table if (found == 0) return; if (log.isDebugEnabled()) { log.debug("Creating table [" + table + "]: " + query); } //ystem.out.println( ">>>> Creating table [" + table + "]: " + query); Statement s = c.createStatement(); try { s.execute(query); } finally { s.close(); } }
From source file:kr.co.bitnine.octopus.testutils.MemoryDatabaseTest.java
private void verifyTableEquals(JSONObject expectedTable, ResultSet actualRows) throws Exception { ResultSetMetaData actualRowsMetaData = actualRows.getMetaData(); JSONArray expectedSchema = (JSONArray) expectedTable.get("table-schema"); assertEquals(expectedSchema.size(), actualRowsMetaData.getColumnCount()); for (int i = 0; i < expectedSchema.size(); i++) assertEquals(expectedSchema.get(i), actualRowsMetaData.getColumnName(i + 1)); for (Object rowObj : (JSONArray) expectedTable.get("table-rows")) { JSONArray row = (JSONArray) rowObj; actualRows.next();/*from w w w . ja va 2 s . c o m*/ for (int i = 0; i < row.size(); i++) { Object expected = row.get(i); Object actual; int sqlType = actualRowsMetaData.getColumnType(i + 1); switch (sqlType) { case Types.INTEGER: if (expected instanceof Boolean) expected = (long) ((Boolean) expected ? 1 : 0); actual = actualRows.getLong(i + 1); break; case Types.NULL: case Types.FLOAT: case Types.VARCHAR: actual = actualRows.getObject(i + 1); break; default: throw new RuntimeException("java.sql.Types " + sqlType + " is not supported"); } assertEquals(expected, actual); } } assertFalse(actualRows.next()); }
From source file:com.mec.DAO.Passport.UserDAO.java
public List<GrantedAuthority> getUserRoles(Integer userID) { SimpleJdbcCall jdbcCall = new SimpleJdbcCall(ds).withCatalogName("SqlSp") .withProcedureName("paRolesGetByIdUsuario").withoutProcedureColumnMetaDataAccess() .declareParameters(new SqlParameter("idAplicacion", Types.INTEGER)) .declareParameters(new SqlParameter("idUsuario", Types.INTEGER)) .declareParameters(new SqlOutParameter("ErrText", Types.VARCHAR)) .returningResultSet("items", new MyRowMapper()); SqlParameterSource in = new MapSqlParameterSource().addValue("idAplicacion", 1).addValue("idUsuario", userID);// w ww .j a v a2s . c om return (List<GrantedAuthority>) jdbcCall.execute(in).entrySet().iterator().next().getValue(); }
From source file:konditer_reorganized_database.dao.CakeDao.java
@Override public void addCake(int cakeId, int customerId, double cakePrice, int orderId, String cakeName, double cakeWeight, String cakePhoto, String cakeKeywords, boolean cakeStatus) throws DataAccessException { String SQL_QUERY = "INSERT INTO cakes ( CAKE_ID, " + "CUSTOMER_ID, " + "CAKE_PRICE, " + "ORDER_ID, " + "CAKE_NAME, " + "CAKE_WEIGHT, " + "CAKE_PHOTO_MINI, " + "CAKE_PHOTO_MAXI, " + "CAKE_KEYWORDS, " + "CAKE_STATUS ) " + "VALUES (?,?,?,?,?,?,?,?,?,?)"; //int cakeId1 = genIdDao.getCakeId(); /*/*from ww w. ja va 2 s . c o m*/ ??? ??? 2- ? ?? ? */ //try{ int rowCount = jdbcTemplate.update(SQL_QUERY, new Object[] { cakeId, customerId, cakePrice, orderId, cakeName, cakeWeight, "" + cakeId + "_s.jpg", "" + cakeId + ".jpg", cakeKeywords, cakeStatus }, new int[] { Types.INTEGER, Types.INTEGER, Types.DOUBLE, Types.INTEGER, Types.VARCHAR, Types.DOUBLE, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BOOLEAN }); Logger.getLogger(CakeDao.class.getName()).log(Level.SEVERE, " : {0} .", rowCount); //}catch(DataAccessException e){ // Logger.getLogger(CakeDao.class.getName()).log(Level.SEVERE, ". ."); //genIdDao.decrementCakeId(); //} }
From source file:iddb.runtime.db.model.dao.impl.mysql.PenaltyDAOImpl.java
@Override public void save(Penalty penalty) { String sql;//from w ww. java2s .c o m if (penalty.getKey() == null) { sql = "insert into penalty (playerid, adminid, type, reason, duration, synced, active, created, updated, expires) values (?,?,?,?,?,?,?,?,?,?)"; } else { sql = "update penalty set playerid = ?," + "adminid = ?," + "type = ?," + "reason = ?," + "duration = ?," + "synced = ?," + "active = ?," + "created = ?," + "updated = ?," + "expires = ? where id = ? limit 1"; } Connection conn = null; try { conn = ConnectionFactory.getMasterConnection(); PreparedStatement st = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); st.setLong(1, penalty.getPlayer()); if (penalty.getAdmin() != null) st.setLong(2, penalty.getAdmin()); else st.setNull(2, Types.INTEGER); st.setInt(3, penalty.getType().intValue()); if (penalty.getReason() != null) st.setString(4, penalty.getReason()); else st.setNull(4, Types.VARCHAR); if (penalty.getDuration() == null) penalty.setDuration(0L); st.setLong(5, penalty.getDuration()); st.setBoolean(6, penalty.getSynced()); st.setBoolean(7, penalty.getActive()); if (penalty.getCreated() == null) penalty.setCreated(new Date()); if (penalty.getUpdated() == null) penalty.setUpdated(new Date()); st.setTimestamp(8, new java.sql.Timestamp(penalty.getCreated().getTime())); st.setTimestamp(9, new java.sql.Timestamp(penalty.getUpdated().getTime())); st.setTimestamp(10, new java.sql.Timestamp( DateUtils.addMinutes(penalty.getCreated(), penalty.getDuration().intValue()).getTime())); if (penalty.getKey() != null) st.setLong(11, penalty.getKey()); st.executeUpdate(); if (penalty.getKey() == null) { ResultSet rs = st.getGeneratedKeys(); if (rs != null && rs.next()) { penalty.setKey(rs.getLong(1)); } else { logger.warn("Couldn't get id for penalty player id {}", penalty.getPlayer()); } } } catch (SQLException e) { logger.error("Save: {}", e); } catch (IOException e) { logger.error("Save: {}", e); } finally { try { if (conn != null) conn.close(); } catch (Exception e) { } } }
From source file:com.wso2telco.aggregatorblacklist.dao.ProvisionDAO.java
public boolean insertMerchantProvision(Integer appID, String subscriber, String operator, String[] merchants) throws SQLException, Exception { Connection con = null;//from www.ja v a 2 s . c om ResultSet rs = null; PreparedStatement insertStatement = null; PreparedStatement selectStatement = null; try { con = DbUtils.getDbConnection(DataSourceNames.WSO2TELCO_DEP_DB); if (con == null) { throw new Exception("Connection not found"); } /** * Set autocommit off to handle the transaction */ con.setAutoCommit(false); StringBuilder selectQueryString = new StringBuilder(" SELECT id "); selectQueryString.append(" FROM "); selectQueryString.append(DatabaseTables.OPERATORS.getTableName()); selectQueryString.append(" WHERE operatorname = '" + operator + "'"); selectStatement = con.prepareStatement(selectQueryString.toString()); rs = selectStatement.executeQuery(); int operatorid = 0; if (rs.next()) { operatorid = rs.getInt("id"); } else { throw new Exception("Operator Not Found"); } for (int i = 0; i < merchants.length; i++) { StringBuilder insertQueryString = new StringBuilder("INSERT INTO "); insertQueryString.append(DatabaseTables.MERCHANTOPCO_BLACKLIST.getTableName()); insertQueryString.append(" (application_id, operator_id, subscriber, merchant) "); insertQueryString.append("VALUES (?, ?, ?, ?)"); insertStatement = con.prepareStatement(insertQueryString.toString()); if (appID == null) { insertStatement.setNull(1, Types.INTEGER); } else { insertStatement.setInt(1, appID); } insertStatement.setInt(2, operatorid); insertStatement.setString(3, subscriber); insertStatement.setString(4, merchants[i]); insertStatement.executeUpdate(); /** * commit the transaction if all success */ con.commit(); } } catch (SQLException e) { /** * rollback if Exception occurs */ con.rollback(); log.error("database operation error in Merachantopco Blacklist Entry : ", e); throw e; } catch (Exception e) { /** * rollback if Exception occurs */ con.rollback(); log.error("Error while Provisioning Merchant : ", e); throw e; } finally { DbUtils.closeAllConnections(selectStatement, con, rs); DbUtils.closeAllConnections(insertStatement, null, null); } return true; }