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:dsd.dao.ParsedInputFilesDAO.java
public static String FetchStoredPath(eFileType fileType, Calendar date) { String storedPath = null;// w w w . jav a 2 s. com try { Connection con = DAOProvider.getDataSource().getConnection(); try { Object[] parameters = new Object[3]; parameters[0] = new Integer(fileType.getCode()); parameters[1] = new Integer(fileType.getCode()); parameters[2] = new Timestamp(date.getTimeInMillis()); ResultSet results = DAOProvider.SelectTableSecure(tableName, " stored_path ", " type = ? and timestamp = (select max(timestamp) from parsed_input_files where type = ? and timestamp <= ?) ", "", con, parameters); while (results.next()) { storedPath = results.getString(1); } } catch (Exception exc) { exc.printStackTrace(); } con.close(); } catch (Exception exc) { exc.printStackTrace(); } return storedPath; }
From source file:FacultyAdvisement.StudentRepository.java
public static Student read(DataSource ds, String key) throws SQLException { String studentSQL = "SElECT * FROM STUDENT JOIN USERTABLE on EMAIL = USERNAME WHERE EMAIL = ?"; Student student = new Student(); if (ds == null) { throw new SQLException("ds is null; Can't get data source"); }//from w ww.java2 s. com Connection conn = ds.getConnection(); if (conn == null) { throw new SQLException("conn is null; Can't get db connection"); } try { PreparedStatement sqlStatement = conn.prepareStatement(studentSQL); sqlStatement.setString(1, key); ResultSet result = sqlStatement.executeQuery(); while (result.next()) { student.setId(result.getString("STUID")); student.setFirstName(result.getString("firstname")); student.setLastName(result.getString("lastname")); student.setMajorCode(result.getString("majorcode")); student.setPhoneNumber(result.getString("phone")); student.setUsername(key); student.setPassword(result.getString("password")); } } finally { conn.close(); } return student; }
From source file:com.keybox.manage.db.AuthDB.java
/** * returns the shared secret based on user id * * @param userId user id/*from w ww .j a v a 2 s . c o m*/ * @return auth object */ public static String getSharedSecret(Long userId) { String sharedSecret = null; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement("select * from users where id like ?"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); if (rs.next()) { sharedSecret = EncryptionUtil.decrypt(rs.getString("otp_secret")); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); return sharedSecret; }
From source file:com.wso2telco.util.DbUtil.java
public static String getContextIDForHashKey(String hashKey) throws AuthenticatorException, SQLException { String sessionDataKey = null; String sql = "select contextid from sms_hashkey_contextid_mapping where hashkey=?"; Connection connection = null; PreparedStatement ps = null;//from ww w .ja v a 2 s . c o m ResultSet rs = null; try { connection = getConnectDBConnection(); ps = connection.prepareStatement(sql); ps.setString(1, hashKey); rs = ps.executeQuery(); while (rs.next()) { sessionDataKey = rs.getString("contextid"); } } catch (SQLException e) { handleException(e.getMessage(), e); } finally { IdentityDatabaseUtil.closeAllConnections(connection, rs, ps); } return sessionDataKey; }
From source file:com.jaspersoft.jasperserver.api.engine.common.virtualdatasourcequery.VirtualSQLDataSource.java
public static Set<String> discoverSchemas(Connection conn) throws SQLException { DatabaseMetaData dbMetaData = conn.getMetaData(); ResultSet rs = null; try {// w ww . jav a 2s . c o m Set<String> set = new LinkedHashSet<String>(); rs = dbMetaData.getSchemas(); while (rs.next()) { String schema = rs.getString(TABLE_SCHEM); if (schema != null) set.add(schema); } return set; } catch (SQLException ex) { log.error("Cannot get schemas", ex); throw ex; } finally { if (rs != null) { try { rs.close(); } catch (Exception ex) { } } } }
From source file:com.concursive.connect.web.webdav.WebdavManager.java
/** * Gets the webdavPassword attribute of the WebdavManager object * * @param db Description of the Parameter * @param username Description of the Parameter * @return The webdavPassword value//from ww w . j a va2 s . co m * @throws SQLException Description of the Exception */ public static String getWebdavPassword(Connection db, String username) throws SQLException { String password = ""; PreparedStatement pst = db.prepareStatement( "SELECT webdav_password " + "FROM users " + "WHERE username = ? " + "AND enabled = ? "); pst.setString(1, username); pst.setBoolean(2, true); ResultSet rs = pst.executeQuery(); if (rs.next()) { password = rs.getString("webdav_password"); } rs.close(); pst.close(); return password; }
From source file:com.wso2telco.core.mnc.resolver.dao.OperatorDAO.java
public static String getOperatorByMCCMNC(String mcc, String mnc) throws MobileNtException { Connection conn = null;//w w w .j a v a 2s . co m PreparedStatement ps = null; ResultSet rs = null; String operator = null; try { String sql = "SELECT operatorname FROM operators WHERE mcc = ? AND mnc = ?"; conn = getDBConnection(); ps = conn.prepareStatement(sql); ps.setString(1, mcc); ps.setString(2, mnc); rs = ps.executeQuery(); while (rs.next()) { operator = rs.getString("operatorname"); log.debug("operator in getOperatorByMCCMNC: " + operator); } } catch (SQLException e) { log.error("database operation error in getOperatorByMCCMNC : ", e); handleException("Error occured while getting operator for mcc : " + mcc + " and mnc : " + mnc + "from the database", e); } catch (Exception e) { log.error("error in getOperatorByMCCMNC : ", e); handleException("Error occured while getting operator for mcc : " + mcc + " and mnc : " + mnc + "from the database", e); } finally { DbUtils.closeAllConnections(ps, conn, rs); } return operator; }
From source file:fll.db.NonNumericNominees.java
/** * Get all subjective categories know for the specified tournament. * // ww w .ja v a 2 s . c om * @throws SQLException */ public static Set<String> getCategories(final Connection connection, final int tournamentId) throws SQLException { final Set<String> result = new HashSet<>(); PreparedStatement get = null; ResultSet rs = null; try { get = connection .prepareStatement("SELECT DISTINCT category FROM non_numeric_nominees WHERE tournament = ?"); get.setInt(1, tournamentId); rs = get.executeQuery(); while (rs.next()) { final String category = rs.getString(1); result.add(category); } } finally { SQLFunctions.close(rs); SQLFunctions.close(get); } return result; }
From source file:Main.java
private static void outputResultSet(ResultSet rs) throws Exception { ResultSetMetaData rsMetaData = rs.getMetaData(); int numberOfColumns = rsMetaData.getColumnCount(); for (int i = 1; i < numberOfColumns + 1; i++) { String columnName = rsMetaData.getColumnName(i); System.out.print(columnName + " "); }//from www . ja v a2 s . c o m System.out.println(); System.out.println("----------------------"); while (rs.next()) { for (int i = 1; i < numberOfColumns + 1; i++) { System.out.print(rs.getString(i) + " "); } } }
From source file:at.molindo.dbcopy.Database.java
private static Map<String, Table> readTables(Connection connection) throws SQLException { Map<String, Table> tables = new HashMap<String, Table>(); DatabaseMetaData meta = connection.getMetaData(); String catalog = connection.getCatalog(); // for each table in current catalog ResultSet rs = meta.getTables(catalog, null, null, null); try {/* w ww .j av a 2s . com*/ while (rs.next()) { String tableName = rs.getString("TABLE_NAME"); Table.Builder table = Table.builder(tableName); // columns String columnsQuery = "select COLUMN_NAME,COLLATION_NAME from information_schema.COLUMNS where TABLE_SCHEMA=? and TABLE_NAME=? order by ORDINAL_POSITION"; Map<String, Column> columns = Utils.executePrepared(connection, columnsQuery, new ColumnHandler(), catalog, tableName); if (columns.isEmpty()) { throw new IllegalStateException("table (" + tableName + ") without columns?"); } table.addColumns(columns.values()); // unique keys String uniqueKeysQuery = "show keys from `" + tableName + "` in `" + catalog + "` where `Non_unique` = 0 and `Null` = ''"; List<Map<String, Object>> uniqueKeyColumns = Utils.executePrepared(connection, uniqueKeysQuery, new MapListHandler()); ListMap<String, Column> uniqeKeys = new ListMap<String, Column>(); for (Map<String, Object> keyColumn : uniqueKeyColumns) { String name = (String) keyColumn.get("INDEX_NAME"); String columnName = (String) keyColumn.get("COLUMN_NAME"); if (name == null) { throw new IllegalStateException("KEY_NAME must not be null"); } if (columnName == null) { throw new IllegalStateException("COLUMN_NAME must not be null"); } Column column = columns.get(columnName); if (column == null) { throw new IllegalStateException("COLUMN_NAME unknown: " + columnName); } uniqeKeys.add(name, column); } for (Map.Entry<String, List<Column>> e : uniqeKeys.entrySet()) { table.addUniqueKey(e.getKey(), e.getValue()); } if (uniqeKeys.isEmpty()) { log.warn("table without primary key not supported: " + tableName); } else { tables.put(tableName, table.build()); } } } finally { Utils.close(rs); } return tables; }