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:edumsg.core.commands.tweet.RetweetCommand.java
@Override public void execute() { try {//from ww w . ja v a2 s . c o m dbConn = PostgresConnection.getDataSource().getConnection(); dbConn.setAutoCommit(true); proc = dbConn.prepareCall("{? = call retweet(?,?)}"); proc.setPoolable(true); proc.registerOutParameter(1, Types.INTEGER); proc.setInt(2, Integer.parseInt(map.get("tweet_id"))); proc.setString(3, map.get("session_id")); proc.execute(); int retweets = proc.getInt(1); root.put("app", map.get("app")); root.put("method", map.get("method")); root.put("status", "ok"); root.put("code", "200"); root.put("retweet_count", retweets); try { CommandsHelp.submit(map.get("app"), mapper.writeValueAsString(root), map.get("correlation_id"), LOGGER); String cacheEntry = UserCache.userCache.get("user_tweets:" + map.get("session_id")); if (cacheEntry != null) { JSONObject cacheEntryJson = new JSONObject(cacheEntry); cacheEntryJson.put("cacheStatus", "invalid"); // System.out.println("invalidated"); UserCache.userCache.set("user_tweets:" + map.get("session_id"), cacheEntryJson.toString()); } String cacheEntry1 = UserCache.userCache.get("timeline:" + map.get("session_id")); if (cacheEntry1 != null) { JSONObject cacheEntryJson = new JSONObject(cacheEntry1); cacheEntryJson.put("cacheStatus", "invalid"); // System.out.println("invalidated"); UserCache.userCache.set("timeline:" + map.get("session_id"), cacheEntryJson.toString()); } String cacheEntry2 = TweetsCache.tweetCache.get("get_earliest_replies:" + map.get("session_id")); if (cacheEntry2 != null) { JSONObject cacheEntryJson = new JSONObject(cacheEntry2); cacheEntryJson.put("cacheStatus", "invalid"); // System.out.println("invalidated"); TweetsCache.tweetCache.set("get_earliest_replies:" + map.get("session_id"), cacheEntryJson.toString()); } String cacheEntry3 = TweetsCache.tweetCache.get("get_replies:" + map.get("session_id")); if (cacheEntry3 != null) { JSONObject cacheEntryJson = new JSONObject(cacheEntry3); cacheEntryJson.put("cacheStatus", "invalid"); // System.out.println("invalidated"); TweetsCache.tweetCache.set("get_replies:" + map.get("session_id"), cacheEntryJson.toString()); } String cacheEntry4 = ListCache.listCache.get("get_list_feeds:" + map.get("session_id")); if (cacheEntry4 != null) { JSONObject cacheEntryJson = new JSONObject(cacheEntry4); cacheEntryJson.put("cacheStatus", "invalid"); // System.out.println("invalidated"); ListCache.listCache.set("get_list_feeds:" + map.get("session_id"), cacheEntryJson.toString()); } } catch (JsonGenerationException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } catch (JsonMappingException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } // catch (JSONException e) { // e.printStackTrace(); // } } catch (PSQLException e) { if (e.getMessage().contains("unique constraint")) { CommandsHelp.handleError(map.get("app"), map.get("method"), "You already retweeted this tweet", map.get("correlation_id"), LOGGER); } else { CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER); } LOGGER.log(Level.SEVERE, e.getMessage(), e); } catch (SQLException e) { CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER); LOGGER.log(Level.SEVERE, e.getMessage(), e); } finally { PostgresConnection.disconnect(null, proc, dbConn); } }
From source file:konditer.client.dao.OrdereDao.java
@Override public void addOrdere(int orderId, int customerId, int orderStatusId, int deliveryId, Date orderDateIncome, Date orderDateEnd, double orderCakePrice, double orderDeliveryPrice, double orderWeight, String orderInsidesId, String orderInfo) { String SQL_QUERY = "INSERT INTO orders ( ORDER_ID, " + "CUSTOMER_ID, " + "ORDER_STATUS_ID, " + "DELIVERY_ID, " + "ORDER_DATE_INCOME, " + "ORDER_DATE_END, " + "ORDER_CAKE_PRICE, " + "ORDER_DELIVERY_PRICE, " + "ORDER_WEIGHT, " + "ORDER_INSIDES_ID, " + "ORDER_INFO ) " + "VALUES (?,?,?,?,?,?,?,?,?,?,?)"; int rowCount = jdbcTemplate.update(SQL_QUERY, new Object[] { orderId, customerId, orderStatusId, deliveryId, orderDateIncome, orderDateEnd, orderCakePrice, orderDeliveryPrice, orderWeight, orderInsidesId, orderInfo }, new int[] { Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, Types.DOUBLE, Types.DOUBLE, Types.DOUBLE, Types.VARCHAR, Types.VARCHAR }); Logger.getLogger(CakeDao.class.getName()).log(Level.SEVERE, " : {0} .", rowCount);//from w w w . j a v a2s . co m System.out.println(ordereDao.getOrdere(orderId).toString()); }
From source file:com.trackplus.ddl.GenericStringValueConverter.java
protected String extractColumnValue(ResultSet resultSet, int columnIdx, int jdbcType) throws SQLException, DDLException { String value = resultSet.getString(columnIdx); if (value != null) { switch (jdbcType) { case Types.NUMERIC: case Types.DECIMAL: break; case Types.BIT: case Types.BOOLEAN: case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: case Types.REAL: case Types.FLOAT: case Types.DOUBLE: { break; }/*from w ww . j a v a2s . c om*/ case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.BINARY: case Types.VARBINARY: case Types.TIME: case Types.CLOB: case Types.ARRAY: case Types.REF: { value = "'" + value.replaceAll("'", "''") + "'"; break; } case Types.DATE: case Types.TIMESTAMP: { Date d = resultSet.getDate(columnIdx); Calendar cal = Calendar.getInstance(); cal.setTime(d); int year = cal.get(Calendar.YEAR); if (year < 1900) { throw new DDLException("Invalid date:" + d); } else { value = "'" + value + "'"; } break; } case Types.BLOB: case Types.LONGVARBINARY: { Blob blobValue = resultSet.getBlob(columnIdx); String str = new String(Base64.encodeBase64(blobValue.getBytes(1l, (int) blobValue.length()))); value = "'" + str + "'"; break; } default: break; } } return value; }
From source file:com.bluecollarcoder.dao.RecipeRepository.java
public void persist(final Recipe recipe) { KeyHolder key = new GeneratedKeyHolder(); jdbc.update((Connection con) -> { PreparedStatement stmt = con.prepareStatement( "insert into recipes (recipe_name, recipe_url, recipe_photo) values (?, ?, ?)", Statement.RETURN_GENERATED_KEYS); stmt.setString(1, recipe.getTitle()); stmt.setString(2, recipe.getUrl()); stmt.setString(3, recipe.getPhotoUrl()); return stmt; }, key);// w w w . ja v a 2 s . c o m Number recipeId = (Number) key.getKeys().get("recipe_id"); for (String name : recipe.getIngredients().keySet()) { key = new GeneratedKeyHolder(); jdbc.update((Connection con) -> { PreparedStatement stmt = con.prepareStatement( "insert into ingredients (ingredient_name) values (?)", Statement.RETURN_GENERATED_KEYS); stmt.setString(1, name); return stmt; }, key); Number ingredientId = (Number) key.getKeys().get("ingredient_id"); String amount = recipe.getIngredients().get(name); jdbc.update("insert into ingredient_amount (recipe_id, ingredient_id, amount) values (?, ?, ?)", new Object[] { recipeId, ingredientId, amount }, new int[] { Types.INTEGER, Types.INTEGER, Types.VARCHAR }); } }
From source file:edumsg.core.commands.tweet.UnRetweetCommand.java
@Override public void execute() { try {/* w w w . jav a 2 s .c o m*/ dbConn = PostgresConnection.getDataSource().getConnection(); dbConn.setAutoCommit(true); proc = dbConn.prepareCall("{? = call unretweet(?,?)}"); proc.setPoolable(true); proc.registerOutParameter(1, Types.INTEGER); proc.setInt(2, Integer.parseInt(map.get("tweet_id"))); proc.setString(3, map.get("session_id")); proc.execute(); int retweets = proc.getInt(1); MyObjectMapper mapper = new MyObjectMapper(); JsonNodeFactory nf = JsonNodeFactory.instance; ObjectNode root = nf.objectNode(); root.put("app", map.get("app")); root.put("method", map.get("method")); root.put("status", "ok"); root.put("code", "200"); root.put("favorites", retweets); try { CommandsHelp.submit(map.get("app"), mapper.writeValueAsString(root), map.get("correlation_id"), LOGGER); String cacheEntry = UserCache.userCache.get("user_tweets:" + map.get("session_id")); if (cacheEntry != null) { JSONObject cacheEntryJson = new JSONObject(cacheEntry); cacheEntryJson.put("cacheStatus", "invalid"); // System.out.println("invalidated"); UserCache.userCache.set("user_tweets:" + map.get("session_id"), cacheEntryJson.toString()); } String cacheEntry1 = UserCache.userCache.get("timeline:" + map.get("session_id")); if (cacheEntry1 != null) { JSONObject cacheEntryJson = new JSONObject(cacheEntry1); cacheEntryJson.put("cacheStatus", "invalid"); // System.out.println("invalidated"); UserCache.userCache.set("timeline:" + map.get("session_id"), cacheEntryJson.toString()); } String cacheEntry2 = TweetsCache.tweetCache.get("get_earliest_replies:" + map.get("session_id")); if (cacheEntry2 != null) { JSONObject cacheEntryJson = new JSONObject(cacheEntry2); cacheEntryJson.put("cacheStatus", "invalid"); // System.out.println("invalidated"); TweetsCache.tweetCache.set("get_earliest_replies:" + map.get("session_id"), cacheEntryJson.toString()); } String cacheEntry3 = TweetsCache.tweetCache.get("get_replies:" + map.get("session_id")); if (cacheEntry3 != null) { JSONObject cacheEntryJson = new JSONObject(cacheEntry3); cacheEntryJson.put("cacheStatus", "invalid"); // System.out.println("invalidated"); TweetsCache.tweetCache.set("get_replies:" + map.get("session_id"), cacheEntryJson.toString()); } String cacheEntry4 = ListCache.listCache.get("get_list_feeds:" + map.get("session_id")); if (cacheEntry4 != null) { JSONObject cacheEntryJson = new JSONObject(cacheEntry4); cacheEntryJson.put("cacheStatus", "invalid"); // System.out.println("invalidated"); ListCache.listCache.set("get_list_feeds:" + map.get("session_id"), cacheEntryJson.toString()); } } catch (JsonGenerationException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } catch (JsonMappingException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } // catch (JSONException e) { // e.printStackTrace(); // } } catch (PSQLException e) { CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER); LOGGER.log(Level.SEVERE, e.getMessage(), e); } catch (SQLException e) { CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER); LOGGER.log(Level.SEVERE, e.getMessage(), e); } finally { PostgresConnection.disconnect(null, proc, dbConn); } }
From source file:org.smigo.log.JdbcLogDao.java
@Override public void log(Log req) { String sql = "INSERT INTO visitlog (sessionage,httpstatus,username,requestedurl,locales,useragent,referer,sessionid,method,xforwardedfor,host,querystring) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"; Object[] args = { req.getSessionAge(), req.getHttpStatus(), req.getRemoteUser(), req.getUrl(), req.getLocales(), req.getUseragent(), req.getReferer(), req.getSessionid(), req.getMethod(), req.getIp(), req.getHost(), req.getQueryString() }; int[] types = new int[args.length]; Arrays.fill(types, Types.VARCHAR); types[0] = Types.INTEGER; types[1] = Types.INTEGER;/*w w w. ja va 2s . c om*/ jdbcTemplate.update(sql, args, types); }
From source file:com.streamsets.pipeline.stage.destination.hive.queryexecutor.HiveQueryExecutorIT.java
@Test public void testExecuteSimpleQuery() throws Exception { HiveQueryExecutor queryExecutor = createExecutor("CREATE TABLE copy AS SELECT * FROM origin"); TargetRunner runner = new TargetRunner.Builder(HiveQueryDExecutor.class, queryExecutor) .setOnRecordError(OnRecordError.STOP_PIPELINE).build(); runner.runInit();/* w w w .j a v a 2 s . c om*/ Record record = RecordCreator.create(); record.set(Field.create("blank line")); runner.runWrite(ImmutableList.of(record)); runner.runDestroy(); assertTableStructure("default.copy", new ImmutablePair("copy.id", Types.INTEGER), new ImmutablePair("copy.name", Types.VARCHAR)); }
From source file:org.smigo.species.JdbcSpeciesDao.java
@Override public int addSpecies(int userId) { MapSqlParameterSource s = new MapSqlParameterSource(); s.addValue("creator", userId, Types.INTEGER); return insertSpecies.executeAndReturnKey(s).intValue(); }
From source file:com.thinkbiganalytics.discovery.util.ParserHelper.java
public static String sqlTypeToHiveType(Integer type) { switch (type) { case Types.BIGINT: return "bigint"; case Types.NUMERIC: case Types.DOUBLE: case Types.DECIMAL: return "double"; case Types.INTEGER: return "int"; case Types.FLOAT: return "float"; case Types.TINYINT: return "tinyint"; case Types.DATE: return "date"; case Types.TIMESTAMP: return "timestamp"; case Types.BOOLEAN: return "boolean"; case Types.BINARY: return "binary"; default://from w w w.jav a2 s. c om return "string"; } }
From source file:de.whs.poodle.repositories.FeedbackRepository.java
public void saveFeedback(FeedbackForm form, int studentId, int courseTermId, StatisticSource source) { // make sure we don't insert an empty string into the database String text = form.getText(); if (text != null && text.trim().isEmpty()) text = null;/* w ww .j a va 2s. c o m*/ jdbc.update("INSERT INTO statistic" + "(difficulty,fun,text,time,completion_status,source,course_term_id,exercise_id,student_id) " + "VALUES(" + "?,?,?,?,?::completion_status,?::statistic_source,?,?,?" + ")", new Object[] { form.getDifficulty(), form.getFun(), text, form.getTime(), form.getStatus(), source, courseTermId, form.getExerciseId(), studentId }, /* we have to specify they types because it can't figure * out the types for null values otherwise */ new int[] { Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER }); }