List of usage examples for java.sql ResultSet getLong
long getLong(String columnLabel) throws SQLException;
ResultSet
object as a long
in the Java programming language. From source file:com.mirth.connect.server.controllers.tests.TestUtils.java
public static void fixMessageIdSequence(String channelId) throws Exception { Connection connection = null; long localChannelId = ChannelController.getInstance().getLocalChannelId(channelId); String database = (String) Donkey.getInstance().getConfiguration().getDonkeyProperties().get("database"); Long maxId = null;//from w w w . ja v a2s .com if (database.equals("derby") || database.equals("mysql") || database.equals("sqlserver")) { Statement statement = null; ResultSet result = null; try { connection = getConnection(); statement = connection.createStatement(); result = statement.executeQuery("SELECT MAX(id) FROM d_m" + localChannelId); result.next(); maxId = result.getLong(1) + 1; close(result); statement.execute("DELETE FROM d_message_sequences WHERE local_channel_id = " + localChannelId); statement.execute( "INSERT INTO d_message_sequences (local_channel_id) VALUES (" + localChannelId + ")"); connection.commit(); } finally { close(result); close(statement); close(connection); } } logger.debug("Message ID sequence updated to: " + maxId); }
From source file:com.ywang.alone.handler.task.AuthTask.java
/** * { 'key':'2597aa1d37d432a','uid':'1020293' } * /*from w ww . jav a 2 s .c o m*/ * @param param * @return */ private static String getUserInfo(String msg) { JSONObject jsonObject = AloneUtil.newRetJsonObject(); JSONObject param = JSON.parseObject(msg); String token = param.getString("key"); String userId = null; if (StringUtils.isEmpty(token)) { jsonObject.put("ret", Constant.RET.NO_ACCESS_AUTH); jsonObject.put("errCode", Constant.ErrorCode.NO_ACCESS_AUTH); jsonObject.put("errDesc", Constant.ErrorDesc.NO_ACCESS_AUTH); return jsonObject.toJSONString(); } Jedis jedis = JedisUtil.getJedis(); Long tokenTtl = jedis.ttl("TOKEN:" + token); if (tokenTtl == -1) { jsonObject.put("ret", Constant.RET.NO_ACCESS_AUTH); jsonObject.put("errCode", Constant.ErrorCode.NO_ACCESS_AUTH); jsonObject.put("errDesc", Constant.ErrorDesc.NO_ACCESS_AUTH); } else { userId = jedis.get("TOKEN:" + token); LoggerUtil.logMsg("uid is " + userId); } JedisUtil.returnJedis(jedis); if (StringUtils.isEmpty(userId)) { jsonObject.put("ret", Constant.RET.NO_ACCESS_AUTH); jsonObject.put("errCode", Constant.ErrorCode.NO_ACCESS_AUTH); jsonObject.put("errDesc", Constant.ErrorDesc.NO_ACCESS_AUTH); return jsonObject.toJSONString(); } String aimUid = param.getString("uid");//uid?? if (StringUtils.isEmpty(aimUid)) { aimUid = userId; } DruidPooledConnection conn = null; PreparedStatement stmt = null; JSONObject data = new JSONObject(); try { conn = DataSourceFactory.getInstance().getConn(); conn.setAutoCommit(false); stmt = conn.prepareStatement("SELECT * FROM USERBASE WHERE USER_ID = ?", Statement.RETURN_GENERATED_KEYS); stmt.setString(1, aimUid); ResultSet userInfoRs = stmt.executeQuery(); if (userInfoRs.next()) { UserInfo userInfo = new UserInfo(); userInfo.setRegTime(userInfoRs.getLong("REG_TIME")); userInfo.setUserId(userInfoRs.getString("USER_ID")); userInfo.setAvatar(userInfoRs.getString("AVATAR")); userInfo.setNickName(userInfoRs.getString("NICKNAME")); userInfo.setAge(userInfoRs.getString("AGE")); userInfo.setHoroscope(userInfoRs.getString("HORO_SCOPE")); userInfo.setHeight(userInfoRs.getString("HEIGHT")); userInfo.setWeight(userInfoRs.getString("WEIGHT")); userInfo.setRoleName(userInfoRs.getString("ROLENAME")); userInfo.setAffection(userInfoRs.getString("AFFECTION")); userInfo.setPurpose(userInfoRs.getString("PURPOSE")); userInfo.setEthnicity(userInfoRs.getString("ETHNICITY")); userInfo.setOccupation(userInfoRs.getString("OCCUPATION")); userInfo.setLivecity(userInfoRs.getString("LIVECITY")); userInfo.setLocation(userInfoRs.getString("LOCATION")); userInfo.setTravelcity(userInfoRs.getString("TRAVELCITY")); userInfo.setMovie(userInfoRs.getString("MOVIE")); userInfo.setMusic(userInfoRs.getString("MUSIC")); userInfo.setBooks(userInfoRs.getString("BOOKS")); userInfo.setFood(userInfoRs.getString("FOOD")); userInfo.setOthers(userInfoRs.getString("OTHERS")); userInfo.setIntro(userInfoRs.getString("INTRO")); userInfo.setLastLoginTime(userInfoRs.getLong("LAST_LOGIN_TIME")); // userInfo.setMessagePwd(userInfoRs // .getString("MESSAGE_PWD")); userInfo.setMessageUser(userInfoRs.getString("MESSAGE_USER")); // userInfo.setOnline("1"); data.put("userInfo", JSONObject.toJSON(userInfo)); PreparedStatement pstmt = conn.prepareStatement( "SELECT * FROM uploads WHERE USER_ID = ? and ENABLING=1", Statement.RETURN_GENERATED_KEYS); pstmt.setString(1, aimUid); ResultSet pSet = pstmt.executeQuery(); JSONArray jsonArray = new JSONArray(); while (pSet.next()) { jsonArray.add(pSet.getString("PHOTO_PATH")); } data.put("photos", JSONObject.toJSON(jsonArray)); jsonObject.put("data", JSONObject.toJSON(data)); pSet.close(); pstmt.close(); } else { jsonObject.put("ret", Constant.RET.SYS_ERR); jsonObject.put("errCode", Constant.ErrorCode.SYS_ERR); jsonObject.put("errDesc", Constant.ErrorDesc.SYS_ERR); } userInfoRs.close(); conn.commit(); conn.setAutoCommit(true); } catch (SQLException e) { LoggerUtil.logServerErr(e); jsonObject.put("ret", Constant.RET.SYS_ERR); jsonObject.put("errCode", Constant.ErrorCode.SYS_ERR); jsonObject.put("errDesc", Constant.ErrorDesc.SYS_ERR); } finally { try { if (null != stmt) { stmt.close(); } if (null != conn) { conn.close(); } } catch (SQLException e) { LoggerUtil.logServerErr(e.getMessage()); } } return jsonObject.toJSONString(); }
From source file:dsd.dao.WorstCaseDAO.java
public static ArrayList<WorstPylonCase> GetAllForPeriod(Calendar startDate, Calendar endDate, boolean traffic, boolean debris) { try {//w w w . j a v a 2s . c o m Connection con = DAOProvider.getDataSource().getConnection(); ArrayList<WorstPylonCase> worstCaseDataList = new ArrayList<WorstPylonCase>(); try { String tableName = GetTableNameForDataType(traffic, debris); Object[] parameters = new Object[2]; parameters[0] = new Timestamp(startDate.getTimeInMillis()); parameters[1] = new Timestamp(endDate.getTimeInMillis()); ResultSet results = DAOProvider.SelectTableSecure(tableName, "*", " timestamp >= ? and timestamp <= ? ", "", con, parameters); while (results.next()) { WorstPylonCase dataTuple = new WorstPylonCase(results.getInt(fields[0])); Pylon pylon = new Pylon(results.getInt(fields[0])); pylon.setN(results.getFloat(fields[1])); pylon.setTx(results.getFloat(fields[2])); pylon.setTy(results.getFloat(fields[3])); pylon.setMx(results.getFloat(fields[4])); pylon.setMy(results.getFloat(fields[5])); pylon.setM(results.getFloat(fields[6])); dataTuple.setPylon(pylon); dataTuple.setID(results.getLong("ID")); dataTuple.setComboNumber(results.getInt(fields[8])); dataTuple.setSafetyFactor(results.getFloat(fields[7])); dataTuple.setTimestamp(results.getTimestamp(fields[9]).getTime()); worstCaseDataList.add(dataTuple); } } catch (Exception exc) { exc.printStackTrace(); } con.close(); return worstCaseDataList; } catch (Exception exc) { exc.printStackTrace(); } return null; }
From source file:wiki.doc.DocIdMapper.java
@Override public DocId mapRow(ResultSet resultSet, int i) throws SQLException { long id = resultSet.getLong("id"); return new DocId(id); }
From source file:wiki.doc.DocMapper.java
@Override public Doc mapRow(ResultSet resultSet, int i) throws SQLException { long id = resultSet.getLong("id"); String title = resultSet.getString("title"); // String text = resultSet.getString("text"); //TODO: Fix/*from w w w .ja va 2s . co m*/ return new Doc(id, title, ""); }
From source file:wiki.result.ResultMapper.java
@Override public Result mapRow(ResultSet resultSet, int i) throws SQLException { long from = resultSet.getLong("fromPage"); long to = resultSet.getLong("toPage"); int indirection = resultSet.getInt("indirection"); int max = resultSet.getInt("max"); long time = resultSet.getLong("timeTaken"); return new Result(from, to, indirection, max, time); }
From source file:com.healthcit.analytics.dao.rowmapper.RoleRowMapper.java
@Override public Role mapRow(ResultSet rs, int index) throws SQLException { Long id = rs.getLong("id"); String name = rs.getString("name"); String displayName = rs.getString("display_name"); return new Role(id, name, displayName); }
From source file:uk.ac.kcl.rowmappers.ColumnKeyRowMapper.java
@Override public Long mapRow(ResultSet rs, int i) throws SQLException { return rs.getLong(0); }
From source file:com.healthcit.analytics.dao.rowmapper.UserRowMapper.java
@Override public User mapRow(ResultSet rs, int index) throws SQLException { Long id = rs.getLong("id"); String userName = rs.getString("username"); String password = rs.getString("password"); Date creationDate = rs.getDate("created_date"); String email = rs.getString("email_addr"); return new User(id, userName, password, email, creationDate); }
From source file:com.example.library.MovieMapper.java
@Override public Movie mapRow(ResultSet rs, int rowNum) throws SQLException { return new Movie(rs.getLong("id"), rs.getString("title"), null, rs.getInt("numSells"), rs.getInt("publishedDate"), null); }