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.tethrnet.manage.db.SystemStatusDB.java
/** * returns all key placement statuses//from w w w .j ava 2 s. co m * * @param con DB connection object * @param userId user id */ private static List<HostSystem> getAllSystemStatus(Connection con, Long userId) { List<HostSystem> hostSystemList = new ArrayList<HostSystem>(); try { PreparedStatement stmt = con.prepareStatement("select * from status where user_id=? order by id asc"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { HostSystem hostSystem = SystemDB.getSystem(con, rs.getLong("id")); hostSystem.setStatusCd(rs.getString("status_cd")); hostSystemList.add(hostSystem); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return hostSystemList; }
From source file:com.keybox.manage.db.SystemStatusDB.java
/** * returns all key placement statuses/* ww w . j av a 2 s. co m*/ * * @param con DB connection object * @param userId user id */ private static List<HostSystem> getAllSystemStatus(Connection con, Long userId) { List<HostSystem> hostSystemList = new ArrayList<>(); try { PreparedStatement stmt = con.prepareStatement("select * from status where user_id=? order by id asc"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { HostSystem hostSystem = SystemDB.getSystem(con, rs.getLong("id")); hostSystem.setStatusCd(rs.getString(STATUS_CD)); hostSystemList.add(hostSystem); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return hostSystemList; }
From source file:com.keybox.manage.db.ProfileDB.java
/** * method to do order by based on the sorted set object for profiles * @return list of profiles/*from w ww. j ava 2 s . c om*/ */ public static SortedSet getProfileSet(SortedSet sortedSet) { ArrayList<Profile> profileList = new ArrayList<>(); String orderBy = ""; if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) { orderBy = " order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection(); } String sql = "select distinct p.* from profiles p "; if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM))) { sql = sql + ", system_map m, system s where m.profile_id = p.id and m.system_id = s.id" + " and (lower(s.display_nm) like ? or lower(s.host) like ?)"; } else if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER))) { sql = sql + ", user_map m, users u where m.profile_id = p.id and m.user_id = u.id" + " and (lower(u.first_nm) like ? or lower(u.last_nm) like ?" + " or lower(u.email) like ? or lower(u.username) like ?)"; } sql = sql + orderBy; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_SYSTEM))) { stmt.setString(1, "%" + sortedSet.getFilterMap().get(FILTER_BY_SYSTEM).toLowerCase() + "%"); stmt.setString(2, "%" + sortedSet.getFilterMap().get(FILTER_BY_SYSTEM).toLowerCase() + "%"); } else if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER))) { stmt.setString(1, "%" + sortedSet.getFilterMap().get(FILTER_BY_USER).toLowerCase() + "%"); stmt.setString(2, "%" + sortedSet.getFilterMap().get(FILTER_BY_USER).toLowerCase() + "%"); stmt.setString(3, "%" + sortedSet.getFilterMap().get(FILTER_BY_USER).toLowerCase() + "%"); stmt.setString(4, "%" + sortedSet.getFilterMap().get(FILTER_BY_USER).toLowerCase() + "%"); } ResultSet rs = stmt.executeQuery(); while (rs.next()) { Profile profile = new Profile(); profile.setId(rs.getLong("id")); profile.setNm(rs.getString("nm")); profile.setDesc(rs.getString("desc")); profileList.add(profile); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } finally { DBUtils.closeConn(con); } sortedSet.setItemList(profileList); return sortedSet; }
From source file:ch.newscron.registration.UserRegistration.java
public static long getShortUrlId(String shortURL) { Connection connection = null; PreparedStatement query = null; ResultSet rs = null; try {/*from w ww. j a v a 2s .c o m*/ connection = connect(); query = connection.prepareStatement("SELECT id FROM ShortURL WHERE shortUrl=?"); query.setString(1, shortURL); rs = query.executeQuery(); rs.next(); long shortURLId = rs.getLong("id"); return shortURLId; } catch (Exception ex) { Logger.getLogger(UserRegistration.class.getName()).log(Level.SEVERE, null, ex); } finally { disconnect(connection, query, rs); } return -1; }
From source file:org.paxml.util.PaxmlUtils.java
public static long getNextExecutionId() { if (true) {//from w w w . ja v a2s . co m return -1; } JdbcTemplate temp = new JdbcTemplate(DBUtils.getPooledDataSource()); return temp.query("select next value for execution_id_seq", new ResultSetExtractor<Long>() { @Override public Long extractData(ResultSet rs) throws SQLException, DataAccessException { rs.next(); return rs.getLong(1); } }); }
From source file:com.keybox.manage.db.ProfileSystemsDB.java
/** * returns a list of system ids for a given profile * * @param con DB con//from w w w .j av a 2 s . c o m * @param profileId profile id * @return list of host systems */ public static List<Long> getSystemIdsByProfile(Connection con, Long profileId) { List<Long> systemIdList = new ArrayList<Long>(); try { PreparedStatement stmt = con.prepareStatement( "select * from system s, system_map m where s.id=m.system_id and m.profile_id=? order by display_nm asc"); stmt.setLong(1, profileId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { systemIdList.add(rs.getLong("id")); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { e.printStackTrace(); } return systemIdList; }
From source file:com.keybox.manage.db.ProfileSystemsDB.java
/** * returns a list of system ids for a given profile * * @param con DB con/*from w ww.j ava 2s .c o m*/ * @param profileId profile id * @param userId user id * @return list of host systems */ public static List<Long> getSystemIdsByProfile(Connection con, Long profileId, Long userId) { List<Long> systemIdList = new ArrayList<Long>(); try { PreparedStatement stmt = con.prepareStatement( "select sm.system_id from system_map sm, user_map um where um.profile_id=sm.profile_id and sm.profile_id=? and um.user_id=?"); stmt.setLong(1, profileId); stmt.setLong(2, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { systemIdList.add(rs.getLong("system_id")); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { e.printStackTrace(); } return systemIdList; }
From source file:DeliverWork.java
private static String saveIntoWeed(RemoteFile remoteFile, String projectId) throws SQLException, UnsupportedEncodingException { String url = "http://59.215.226.174/WebDiskServerDemo/doc?doc_id=" + URLEncoder.encode(remoteFile.getFileId(), "utf-8"); CloseableHttpClient httpClient = null; CloseableHttpResponse response = null; String res = ""; try {//from w w w. j a v a 2 s. c om httpClient = HttpClients.createSystem(); // http(get?) HttpGet httpget = new HttpGet(url); response = httpClient.execute(httpget); HttpEntity result = response.getEntity(); String fileName = remoteFile.getFileName(); FileHandleStatus fileHandleStatus = getFileTemplate().saveFileByStream(fileName, new ByteArrayInputStream(EntityUtils.toByteArray(result))); System.out.println(fileHandleStatus); File file = new File(); if (result != null && result.getContentType() != null && result.getContentType().getValue() != null) { file.setContentType(result.getContentType().getValue()); } else { file.setContentType("application/error"); } file.setDataId(Integer.parseInt(projectId)); file.setName(fileName); if (fileName.contains(".bmp") || fileName.contains(".jpg") || fileName.contains(".jpeg") || fileName.contains(".png") || fileName.contains(".gif")) { file.setType(1); } else if (fileName.contains(".doc") || fileName.contains(".docx")) { file.setType(2); } else if (fileName.contains(".xlsx") || fileName.contains("xls")) { file.setType(3); } else if (fileName.contains(".pdf")) { file.setType(4); } else { file.setType(5); } String accessUrl = "/" + fileHandleStatus.getFileId().replaceAll(",", "/").concat("/").concat(fileName); file.setUrl(accessUrl); file.setSize(fileHandleStatus.getSize()); file.setPostTime(new java.util.Date()); file.setStatus(0); file.setEnumValue(findFileType(remoteFile.getFileType())); file.setResources(1); // JdbcFactory jdbcFactoryChanye=new JdbcFactory("jdbc:mysql://127.0.0.1:3306/fp_guimin?useUnicode=true&characterEncoding=UTF-8","root","111111","com.mysql.jdbc.Driver"); // Connection connection = jdbcFactoryChanye.getConnection(); DatabaseMetaData dmd = connection.getMetaData(); PreparedStatement ps = connection.prepareStatement(insertFile, new String[] { "ID" }); ps.setString(1, sdf.format(file.getPostTime())); ps.setInt(2, file.getType()); ps.setString(3, file.getEnumValue()); ps.setInt(4, file.getDataId()); ps.setString(5, file.getUrl()); ps.setString(6, file.getName()); ps.setString(7, file.getContentType()); ps.setLong(8, file.getSize()); ps.setInt(9, file.getStatus()); ps.setInt(10, file.getResources()); ps.executeUpdate(); if (dmd.supportsGetGeneratedKeys()) { ResultSet rs = ps.getGeneratedKeys(); while (rs.next()) { System.out.println(rs.getLong(1)); } } ps.close(); res = "success"; } catch (ClientProtocolException e) { e.printStackTrace(); res = e.getMessage(); } catch (IOException e) { e.printStackTrace(); res = e.getMessage(); } catch (Exception ex) { ex.printStackTrace(); } finally { if (httpClient != null) { try { httpClient.close(); } catch (IOException e) { e.printStackTrace(); } } if (response != null) { try { response.close(); } catch (IOException e) { e.printStackTrace(); } } } return res; }
From source file:org.ulyssis.ipp.snapshot.Event.java
public static List<Event> loadFrom(Connection connection, Instant time) throws SQLException, IOException { String statement = "SELECT \"id\",\"data\",\"removed\" FROM \"events\" " + "WHERE \"time\" >= ? ORDER BY \"time\" ASC, \"id\" ASC"; List<Event> events = new ArrayList<>(); try (PreparedStatement stmt = connection.prepareStatement(statement)) { stmt.setTimestamp(1, Timestamp.from(time)); ResultSet rs = stmt.executeQuery(); while (rs.next()) { String evString = rs.getString("data"); Event event = Serialization.getJsonMapper().readValue(evString, Event.class); event.id = rs.getLong("id"); event.removed = rs.getBoolean("removed"); events.add(event);/* w w w . j a v a2 s.c o m*/ } } return events; }
From source file:org.ulyssis.ipp.snapshot.Event.java
public static List<Event> loadAfter(Connection connection, Instant time, long id) throws SQLException, IOException { String statement = "SELECT \"id\",\"data\",\"removed\" FROM \"events\" " + "WHERE \"time\" > ? OR (\"time\" = ? AND \"id\" > ?) ORDER BY \"time\" ASC, \"id\" ASC"; List<Event> events = new ArrayList<>(); try (PreparedStatement stmt = connection.prepareStatement(statement)) { stmt.setTimestamp(1, Timestamp.from(time)); stmt.setTimestamp(2, Timestamp.from(time)); stmt.setLong(3, id);//ww w . j av a 2s .c om LOG.debug("Executing query: {}", stmt); ResultSet rs = stmt.executeQuery(); while (rs.next()) { String evString = rs.getString("data"); Event event = Serialization.getJsonMapper().readValue(evString, Event.class); event.id = rs.getLong("id"); event.removed = rs.getBoolean("removed"); events.add(event); } } LOG.debug("Loaded {} events", events.size()); return events; }