Java Code Examples for java.sql.SQLException.getStackTrace()

The following are Jave code examples for showing how to use getStackTrace() of the java.sql.SQLException class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: orbis-lps2ima-dev   File: BaseServerImpl.java   View Source Code Vote up 6 votes
/**
 * Test if the user name and password are correct.
 * @param username Name of the user.
 * @param password Password of the user.
 * @return True if the user is correct, false otherwise.
 */
private boolean testUser(String username, String password){
    try {
        PreparedStatement ps = ds.getConnection().prepareStatement(
                "SELECT COUNT(username) FROM session_table WHERE username LIKE ? AND password LIKE ?;");
        ps.setString(1, username);
        ps.setString(2, password);
        ResultSet rs = ps.executeQuery();
        rs.first();
        boolean isUser = rs.getInt(1) != 0;
        rs.close();
        return isUser;
    } catch (SQLException e) {
        LOGGER.error("Unable to request the database in order to test username/password.\n"+e.getLocalizedMessage());
        for(StackTraceElement el : e.getStackTrace()){
            LOGGER.error(el.toString());
        }
    }
    return false;
}
 
Example 2
Project: orbis-lps2ima-dev   File: BaseServerImpl.java   View Source Code Vote up 6 votes
/**
 * Test if the user name is correct.
 * @param username Name of the user.
 * @return True if the user is correct, false otherwise.
 */
private boolean testUser(String username){
    try {
        PreparedStatement ps = ds.getConnection().prepareStatement(
                "SELECT COUNT(username) FROM session_table WHERE username LIKE ?;");
        ps.setString(1, username);
        ResultSet rs = ps.executeQuery();
        rs.first();
        boolean isUser = rs.getInt(1) != 0;
        rs.close();
        return isUser;
    } catch (SQLException e) {
        LOGGER.error("Unable to request the database in order to test username.\n"+e.getLocalizedMessage());
        for(StackTraceElement el : e.getStackTrace()){
            LOGGER.error(el.toString());
        }
    }
    return false;
}