List of usage examples for java.sql ResultSet getString
String getString(String columnLabel) throws SQLException;
ResultSet
object as a String
in the Java programming language. From source file:at.becast.youploader.account.Account.java
public static Account read(int id) throws IOException { PreparedStatement stmt;//from w w w . j a v a2 s. c om try { stmt = c.prepareStatement("SELECT * FROM `accounts` WHERE `id`=? LIMIT 1"); stmt.setInt(1, id); ResultSet rs = stmt.executeQuery(); ObjectMapper mapper = new ObjectMapper(); List<Cookie> c = mapper.readValue(rs.getString("cookie"), new TypeReference<List<Cookie>>() { }); String name = rs.getString("name"); String token = rs.getString("refresh_token"); stmt.close(); rs.close(); return new Account(id, name, token, c); } catch (SQLException e) { LOG.error("Account read error!", e); return null; } }
From source file:org.ulyssis.ipp.snapshot.Snapshot.java
public static Optional<Snapshot> loadForEvent(Connection connection, Event event) throws SQLException, IOException { String statement = "SELECT \"id\", \"data\" FROM \"snapshots\" WHERE \"event\" = ?"; try (PreparedStatement stmt = connection.prepareStatement(statement)) { stmt.setLong(1, event.getId().get()); LOG.debug("executing query: {}", stmt); ResultSet rs = stmt.executeQuery(); if (rs.next()) { String data = rs.getString("data"); Snapshot result = Serialization.getJsonMapper().readValue(data, Snapshot.class); result.id = rs.getLong("id"); result.eventId = event.getId().get(); return Optional.of(result); } else {/*www. jav a2s . c o m*/ return Optional.empty(); } } }
From source file:com.handany.base.generator.Generator.java
public static List<ColumnBean> getColumns(final TableBean tableBean) { return jdbcTemplate.query("select * from COLUMNS where table_schema = ? and table_name = ?", new Object[] { SCHEMA_NAME, tableBean.getTableName() }, new RowMapper<ColumnBean>() { @Override//from w ww . ja va2 s.co m public ColumnBean mapRow(ResultSet rs, int i) throws SQLException { ColumnBean columnBean = new ColumnBean(); String columnName = rs.getString("column_name"); columnBean.setColumnName(columnName); columnBean.setColumnNameNoDash(delDash(columnName)); columnBean .setColumnNameCapitalized(StringUtils.capitalize(columnBean.getColumnNameNoDash())); columnBean.setColumnComment(rs.getString("column_comment")); String charLength = rs.getString("character_maximum_length"); if (StringUtils.isNoneBlank(charLength)) { columnBean.setLength(Long.parseLong(charLength)); } String columnType = rs.getString("column_type").toLowerCase(); if (columnType.startsWith("varchar") || columnType.startsWith("char") || columnType.startsWith("clob") || ("text").equals(columnType) || ("longtext").equals(columnType) || columnType.startsWith("enum")) { columnBean.setColumnType("String"); columnBean.setColumnTypeRsGetter("getString"); } else if (columnType.startsWith("tinyint") || columnType.startsWith("smallint") || columnType.startsWith("mediumint")) { columnBean.setColumnType("Integer"); columnBean.setColumnTypeRsGetter("getInt"); } else if (columnType.startsWith("int") || columnType.startsWith("bigint")) { columnBean.setColumnType("Long"); columnBean.setColumnTypeRsGetter("getLong"); } else if (("timestamp").equals(columnType) || ("datetime").equals(columnType) || ("date").equals(columnType)) { columnBean.setColumnType("Date"); columnBean.setColumnTypeRsGetter("getDate"); tableBean.setHasDateColumn(true); } else if (columnType.startsWith("float")) { columnBean.setColumnType("Float"); columnBean.setColumnTypeRsGetter("getFloat"); } else if (columnType.startsWith("double")) { columnBean.setColumnType("Double"); columnBean.setColumnTypeRsGetter("getDouble"); } else if (columnType.startsWith("decimal")) { columnBean.setColumnType("BigDecimal"); columnBean.setColumnTypeRsGetter("getBigDecimal"); tableBean.setHasBigDecimal(true); } else { throw new RuntimeException("Unsupported type: [" + columnType + "]!"); } String dataType = rs.getString("data_type").toUpperCase(); if ("DATETIME".equals(dataType)) { dataType = "TIMESTAMP"; } else if ("TEXT".equals(dataType)) { dataType = "LONGVARCHAR"; } columnBean.setColumnJdbcType(dataType); return columnBean; } }); }
From source file:org.red5.webapps.admin.controllers.service.UserDAO.java
public static AdminUserDetails getUser(String username) { AdminUserDetails details = null;/*from w ww.java 2 s.c om*/ Connection conn = null; PreparedStatement stmt = null; try { conn = UserDatabase.getConnection(); //make a statement stmt = conn.prepareStatement("SELECT * FROM APPUSER WHERE username = ?"); stmt.setString(1, username); ResultSet rs = stmt.executeQuery(); if (rs.next()) { log.debug("User found"); details = new AdminUserDetails(); details.setEnabled("enabled".equals(rs.getString("enabled"))); details.setPassword(rs.getString("password")); details.setUserid(rs.getInt("userid")); details.setUsername(rs.getString("username")); // rs.close(); //get role stmt = conn.prepareStatement("SELECT authority FROM APPROLE WHERE username = ?"); stmt.setString(1, username); rs = stmt.executeQuery(); if (rs.next()) { GrantedAuthority[] authorities = new GrantedAuthority[1]; authorities[0] = new GrantedAuthorityImpl(rs.getString("authority")); details.setAuthorities(authorities); // //if (daoAuthenticationProvider != null) { //User usr = new User(username, details.getPassword(), true, true, true, true, authorities); //daoAuthenticationProvider.getUserCache().putUserInCache(usr); //} } } rs.close(); } catch (Exception e) { log.error("Error connecting to db", e); } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException e) { } } if (conn != null) { UserDatabase.recycle(conn); } } return details; }
From source file:org.ulyssis.ipp.snapshot.Snapshot.java
public static Optional<Snapshot> loadBefore(Connection connection, Instant time) throws SQLException, IOException { String statement = "SELECT \"id\", \"data\", \"event\" FROM \"snapshots\" " + "WHERE \"time\" < ? ORDER BY \"time\" DESC, \"event\" DESC FETCH FIRST ROW ONLY"; try (PreparedStatement stmt = connection.prepareStatement(statement)) { stmt.setTimestamp(1, Timestamp.from(time)); LOG.debug("Executing query: {}", stmt); ResultSet rs = stmt.executeQuery(); if (rs.next()) { String data = rs.getString("data"); Snapshot result = Serialization.getJsonMapper().readValue(data, Snapshot.class); result.id = rs.getLong("id"); result.eventId = rs.getLong("event"); return Optional.of(result); } else {/*from w w w .j av a 2 s . c o m*/ return Optional.empty(); } } }
From source file:com.bluepandora.therap.donatelife.gcmservice.FindDonator.java
/** * * @param groupId// w w w. j a v a 2 s .c o m * @param hospitalId * @param mobileNumber * @return This function will return the List of GCM ID without Requester * mobileNumber's GCM ID; */ public static List findDonatorGCMId(String groupId, String hospitalId, DatabaseService dbService) { String query = GetQuery.findBestDonatorQuery(groupId, hospitalId); Debug.debugLog("FIND DONATOR: ", query); ResultSet result = dbService.getResultSet(query); List donatorList = new ArrayList<String>(); Debug.debugLog("DONATOR GCM ID FINDING"); try { while (result.next()) { String mobileNumber = result.getString("mobile_number"); String gcmId = result.getString("gcm_id"); if (gcmId.length() > VALID_GCM_SIZE_GREATER) { Debug.debugLog("Mobile: ", mobileNumber, "GCM Id: ", gcmId); donatorList.add(gcmId); } } } catch (SQLException error) { Debug.debugLog("FINDING DONATOR'S GCM SQL EXCEPTION!"); } return donatorList; }
From source file:org.springside.modules.test.data.H2Fixtures.java
/** * ,excludeTables.disable./*ww w. java 2 s . co m*/ */ public static void deleteAllTable(DataSource dataSource, String... excludeTables) { List<String> tableNames = new ArrayList<String>(); ResultSet rs = null; try { rs = dataSource.getConnection().getMetaData().getTables(null, null, null, new String[] { "TABLE" }); while (rs.next()) { String tableName = rs.getString("TABLE_NAME"); if (Arrays.binarySearch(excludeTables, tableName) < 0) { tableNames.add(tableName); } } deleteTable(dataSource, tableNames.toArray(new String[tableNames.size()])); } catch (SQLException e) { Exceptions.unchecked(e); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
From source file:com.sql.SystemErrorEmailList.java
/** * Gathers a list of active email addresses to send to for the email * for the daily crash report email./*from ww w . j ava 2 s . co m*/ * * @return */ public static List<String> getActiveEmailAddresses() { List<String> list = new ArrayList(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT EmailAddress " + "FROM SystemErrorEmailList " + "WHERE active = 1"; ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { if (rs.getString("EmailAddress") != null) { list.add(rs.getString("EmailAddress")); } } } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return list; }
From source file:com.pinterest.pinlater.backends.mysql.MySQLBackendUtils.java
/** * Gets the names of all queues found at the specified MySQL instance. Note that it is the * callers responsibility to close the connection after this method is called. * * @param conn Connection to the MySQL instance. * @param shardName/* w w w .jav a 2 s .c o m*/ * @return Set containing queue name strings. */ public static Set<String> getQueueNames(Connection conn, String shardName) throws SQLException { ResultSet dbNameRs = conn.getMetaData().getCatalogs(); Set<String> queueNames = Sets.newHashSet(); while (dbNameRs.next()) { String name = dbNameRs.getString("TABLE_CAT"); if (name.startsWith(MySQLBackendUtils.PINLATER_QUEUE_DB_PREFIX) && shardNameFromDBName(name).equals(shardName)) { queueNames.add(MySQLBackendUtils.queueNameFromDBName(name)); } } return queueNames; }
From source file:org.red5.server.plugin.admin.dao.UserDAO.java
public static UserDetails getUser(String username) { UserDetails details = null;//from www . j av a 2 s.c o m Connection conn = null; PreparedStatement stmt = null; try { // JDBC stuff DataSource ds = UserDatabase.getDataSource(); conn = ds.getConnection(); //make a statement stmt = conn.prepareStatement("SELECT * FROM APPUSER WHERE username = ?"); stmt.setString(1, username); ResultSet rs = stmt.executeQuery(); if (rs.next()) { log.debug("User found"); details = new UserDetails(); details.setEnabled("enabled".equals(rs.getString("enabled"))); details.setPassword(rs.getString("password")); details.setUserid(rs.getInt("userid")); details.setUsername(rs.getString("username")); // rs.close(); //get role stmt = conn.prepareStatement("SELECT authority FROM APPROLE WHERE username = ?"); stmt.setString(1, username); rs = stmt.executeQuery(); if (rs.next()) { Collection<? extends GrantedAuthority> authorities; // authorities.addAll((Collection<?>) new GrantedAuthorityImpl(rs.getString("authority"))); // details.setAuthorities(authorities); // //if (daoAuthenticationProvider != null) { //User usr = new User(username, details.getPassword(), true, true, true, true, authorities); //daoAuthenticationProvider.getUserCache().putUserInCache(usr); //} } } rs.close(); } catch (Exception e) { log.error("Error connecting to db", e); } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException e) { } } if (conn != null) { try { conn.close(); } catch (SQLException e) { } } } return details; }