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:net.codjo.dataprocess.server.treatmenthelper.TreatmentHelper.java
private static List<TreatmentFragment> checkIntegrityRepositoryContent(Connection con) throws SQLException { List<TreatmentFragment> treatmentFragmentList = new ArrayList<TreatmentFragment>(); Statement stmt = con.createStatement(); try {// w w w .j av a 2 s . c o m ResultSet rs = stmt.executeQuery("select TREATMENT_ID, CONTENT from PM_REPOSITORY_CONTENT " + " where CONTENT not like '%</" + DataProcessConstants.TREATMENT_ENTITY_XML + ">%'"); try { while (rs.next()) { String content = rs.getString("CONTENT"); String contentFragment = content.substring(content.length() - LENGTH) .replace(DataProcessConstants.SPECIAL_CHAR_REPLACER_N, " ") .replace(DataProcessConstants.SPECIAL_CHAR_REPLACER_R, " "); treatmentFragmentList.add(new TreatmentFragment(rs.getString("TREATMENT_ID"), contentFragment)); } return treatmentFragmentList; } finally { rs.close(); } } finally { stmt.close(); } }
From source file:com.mirth.connect.server.util.DatabaseUtil.java
/** * Tell whether or not the given index exists in the database *//*from www. j av a2 s . c o m*/ public static boolean indexExists(Connection connection, String tableName, String indexName) { if (!tableExists(connection, tableName)) { return false; } ResultSet resultSet = null; try { DatabaseMetaData metaData = connection.getMetaData(); resultSet = metaData.getIndexInfo(null, null, tableName.toUpperCase(), false, false); while (resultSet.next()) { if (indexName.equalsIgnoreCase(resultSet.getString("INDEX_NAME"))) { return true; } } resultSet = metaData.getIndexInfo(null, null, tableName.toLowerCase(), false, false); while (resultSet.next()) { if (indexName.equalsIgnoreCase(resultSet.getString("INDEX_NAME"))) { return true; } } return false; } catch (SQLException e) { throw new DonkeyDaoException(e); } finally { DbUtils.closeQuietly(resultSet); } }
From source file:com.xqdev.sql.MLSQL.java
private static void addGeneratedKeys(Element meta, ResultSet keys) throws SQLException { Namespace sql = meta.getNamespace(); while (keys.next()) { // should only be one meta.addContent(new Element("generated-key", sql).setText("" + keys.getString(1))); }/* w w w. ja v a 2 s. c om*/ }
From source file:cn.clickvalue.cv2.model.rowmapper.BeanPropertyRowMapper.java
/** * Retrieve a JDBC column value from a ResultSet, using the most appropriate * value type. The returned value should be a detached value object, not having * any ties to the active ResultSet: in particular, it should not be a Blob or * Clob object but rather a byte array respectively String representation. * <p>Uses the <code>getObject(index)</code> method, but includes additional "hacks" * to get around Oracle 10g returning a non-standard object for its TIMESTAMP * datatype and a <code>java.sql.Date</code> for DATE columns leaving out the * time portion: These columns will explicitly be extracted as standard * <code>java.sql.Timestamp</code> object. * @param rs is the ResultSet holding the data * @param index is the column index// w ww . jav a 2s. com * @return the value object * @throws SQLException if thrown by the JDBC API * @see java.sql.Blob * @see java.sql.Clob * @see java.sql.Timestamp */ public static Object getResultSetValue(ResultSet rs, int index) throws SQLException { Object obj = rs.getObject(index); if (obj instanceof Blob) { obj = rs.getBytes(index); } else if (obj instanceof Clob) { obj = rs.getString(index); } else if (obj != null && obj.getClass().getName().startsWith("oracle.sql.TIMESTAMP")) { obj = rs.getTimestamp(index); } else if (obj != null && obj.getClass().getName().startsWith("oracle.sql.DATE")) { String metaDataClassName = rs.getMetaData().getColumnClassName(index); if ("java.sql.Timestamp".equals(metaDataClassName) || "oracle.sql.TIMESTAMP".equals(metaDataClassName)) { obj = rs.getTimestamp(index); } else { obj = rs.getDate(index); } } else if (obj != null && obj instanceof java.sql.Date) { if ("java.sql.Timestamp".equals(rs.getMetaData().getColumnClassName(index))) { obj = rs.getTimestamp(index); } } return obj; }
From source file:com.tethrnet.manage.db.UserDB.java
/** * returns user base on id//from w ww.ja v a 2 s . c om * @param con DB connection * @param userId user id * @return user object */ public static User getUser(Connection con, Long userId) { User user = null; try { PreparedStatement stmt = con.prepareStatement("select * from users where id=?"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { user = new User(); user.setId(rs.getLong("id")); user.setEmail(rs.getString("email")); user.setUsername(rs.getString("username")); user.setPassword(rs.getString("password")); user.setAuthType(rs.getString("auth_type")); user.setUserType(rs.getString("user_type")); user.setSalt(rs.getString("salt")); user.setProfileList(UserProfileDB.getProfilesByUser(con, userId)); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return user; }
From source file:com.tethrnet.manage.db.AuthDB.java
/** * returns user base on username/* ww w. jav a2 s. c o m*/ * * @param con DB connection * @param uid username id * @return user object */ public static User getUserByUID(Connection con, String uid) { User user = null; try { PreparedStatement stmt = con .prepareStatement("select * from users where lower(username) like lower(?) and enabled=true"); stmt.setString(1, uid); ResultSet rs = stmt.executeQuery(); while (rs.next()) { user = new User(); user.setId(rs.getLong("id")); user.setEmail(rs.getString("email")); user.setUsername(rs.getString("username")); user.setUserType(rs.getString("user_type")); user.setProfileList(UserProfileDB.getProfilesByUser(con, user.getId())); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return user; }
From source file:fll.Team.java
/** * Builds a team object from its database info given the team number. * /* w ww. j a va2s .c o m*/ * @param connection Database connection. * @param teamNumber Number of the team for which to build an object. * @return The new Team object or null if the team was not found in the * database. * @throws SQLException on a database access error. */ public static Team getTeamFromDatabase(final Connection connection, final int teamNumber) throws SQLException { // First, handle known non-database team numbers... if (teamNumber == NULL_TEAM_NUMBER) { return NULL; } if (teamNumber == TIE_TEAM_NUMBER) { return TIE; } if (teamNumber == BYE_TEAM_NUMBER) { return BYE; } PreparedStatement stmt = null; ResultSet rs = null; try { stmt = connection.prepareStatement( "SELECT Division, Organization, TeamName FROM Teams" + " WHERE TeamNumber = ?"); stmt.setInt(1, teamNumber); rs = stmt.executeQuery(); if (rs.next()) { final String division = rs.getString(1); final String org = rs.getString(2); final String name = rs.getString(3); final Team x = new Team(teamNumber, org, name, division); return x; } else { return null; } } finally { SQLFunctions.close(rs); SQLFunctions.close(stmt); } }
From source file:com.keybox.manage.db.AuthDB.java
/** * returns user base on username//from w ww.j a v a 2 s .c o m * * @param con DB connection * @param uid username id * @return user object */ public static User getUserByUID(Connection con, String uid) { User user = null; try { PreparedStatement stmt = con .prepareStatement("select * from users where lower(username) like lower(?) and enabled=true"); stmt.setString(1, uid); ResultSet rs = stmt.executeQuery(); while (rs.next()) { user = new User(); user.setId(rs.getLong("id")); user.setFirstNm(rs.getString("first_nm")); user.setLastNm(rs.getString("last_nm")); user.setEmail(rs.getString("email")); user.setUsername(rs.getString("username")); user.setUserType(rs.getString("user_type")); user.setProfileList(UserProfileDB.getProfilesByUser(con, user.getId())); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } return user; }
From source file:com.concursive.connect.web.webdav.WebdavManager.java
public static int validateUser(Connection db, HttpServletRequest req) throws Exception { String argHeader = req.getHeader("Authorization"); HashMap params = getAuthenticationParams(argHeader); String username = (String) params.get("username"); if (md5Helper == null) { md5Helper = MessageDigest.getInstance("MD5"); }/* w w w . j a v a2s. com*/ int userId = -1; String password = null; PreparedStatement pst = db.prepareStatement( "SELECT user_id, webdav_password " + "FROM users " + "WHERE username = ? " + "AND enabled = ? "); pst.setString(1, username); pst.setBoolean(2, true); ResultSet rs = pst.executeQuery(); if (rs.next()) { userId = rs.getInt("user_id"); password = rs.getString("webdav_password"); } rs.close(); pst.close(); if (userId == -1) { return userId; } String method = req.getMethod(); String uri = (String) params.get("uri"); String a2 = MD5Encoder.encode(md5Helper.digest((method + ":" + uri).getBytes())); String digest = MD5Encoder .encode(md5Helper.digest((password + ":" + params.get("nonce") + ":" + a2).getBytes())); if (!digest.equals(params.get("response"))) { userId = -1; } return userId; }
From source file:com.tethrnet.manage.db.UserDB.java
/** * returns users based on sort order defined * @param sortedSet object that defines sort order * @return sorted user list//from w w w . j a v a 2 s . c o m */ public static SortedSet getUserSet(SortedSet sortedSet) { ArrayList<User> userList = new ArrayList<User>(); String orderBy = ""; if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) { orderBy = "order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection(); } String sql = "select * from users where enabled=true " + orderBy; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); ResultSet rs = stmt.executeQuery(); while (rs.next()) { User user = new User(); user.setId(rs.getLong("id")); user.setEmail(rs.getString("email")); user.setUsername(rs.getString("username")); user.setPassword(rs.getString("password")); user.setAuthType(rs.getString("auth_type")); user.setUserType(rs.getString("user_type")); userList.add(user); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); sortedSet.setItemList(userList); return sortedSet; }