Example usage for java.sql CallableStatement executeQuery

List of usage examples for java.sql CallableStatement executeQuery

Introduction

In this page you can find the example usage for java.sql CallableStatement executeQuery.

Prototype

ResultSet executeQuery() throws SQLException;

Source Link

Document

Executes the SQL query in this PreparedStatement object and returns the ResultSet object generated by the query.

Usage

From source file:dbProcs.Getter.java

/**
 * Used to decipher whether or not a user exists as a player
 * @param userId The user identifier of the player to be found
 * @return A boolean reflecting the state of existence of the player
 *//*  w  ww . j  a v  a2 s  .  c om*/
public static boolean findPlayerById(String ApplicationRoot, String userId) {
    log.debug("*** Getter.findPlayerById ***");
    boolean userFound = false;
    //Get connection
    Connection conn = Database.getCoreConnection(ApplicationRoot);
    try {
        CallableStatement callstmt = conn.prepareCall("call playerFindById(?)");
        log.debug("Gathering playerFindById ResultSet");
        callstmt.setString(1, userId);
        ResultSet userFind = callstmt.executeQuery();
        log.debug("Opening Result Set from playerFindById");
        userFind.next(); //This will throw an exception if player not found
        log.debug("Player Found: " + userFind.getString(1)); //This line will not execute if player not found
        userFound = true;
    } catch (Exception e) {
        log.error("Player did not exist: " + e.toString());
        userFound = false;
    }
    Database.closeConnection(conn);
    log.debug("*** END findPlayerById ***");
    return userFound;
}

From source file:dbProcs.Getter.java

/**
 * @param ApplicationRoot The current running context of the application
 * @param userId The identifier of a user
 * @return The user name of the submitted user identifier
 *///w ww  .  j a  va2  s. c  om
public static String getUserName(String ApplicationRoot, String userId) {
    log.debug("*** Getter.getUserName ***");
    String result = new String();
    Connection conn = Database.getCoreConnection(ApplicationRoot);
    try {
        CallableStatement callstmt = conn.prepareCall("call userGetNameById(?)");
        log.debug("Gathering userGetNameById ResultSet");
        callstmt.setString(1, userId);
        ResultSet resultSet = callstmt.executeQuery();
        log.debug("Opening Result Set from userGetNameById");
        resultSet.next();
        result = resultSet.getString(1);
    } catch (SQLException e) {
        log.error("Could not execute query: " + e.toString());
        result = null;
    }
    Database.closeConnection(conn);
    log.debug("*** END getUserName ***");
    return result;
}

From source file:dbProcs.Getter.java

/**
 * @param applicationRoot The current running context of the application.
 * @param moduleId The identifier of a module
 * @return The hash of the module specified
 *//*from w ww  .  ja v  a  2s  .  co  m*/
public static String getModuleHash(String applicationRoot, String moduleId) {
    log.debug("*** Getter.getModuleHash ***");
    String result = new String();
    Connection conn = Database.getCoreConnection(applicationRoot);
    try {
        CallableStatement callstmt = conn.prepareCall("call moduleGetHashById(?)");
        log.debug("Gathering moduleGetHash ResultSet");
        callstmt.setString(1, moduleId);
        ResultSet resultSet = callstmt.executeQuery();
        log.debug("Opening Result Set from moduleGetHash");
        resultSet.next();
        result = resultSet.getString(1);
    } catch (SQLException e) {
        log.error("Could not execute moduleGetHash: " + e.toString());
        result = null;
    }
    Database.closeConnection(conn);
    log.debug("*** END getModuleHash ***");
    return result;
}

From source file:dbProcs.Getter.java

/**
 * @param ApplicationRoot The current running context of the application
 * @param userName The username of the user
 * @return The user id of the submitted user name
 *///from w w w  . j a v  a2 s  .c  om
public static String getUserIdFromName(String ApplicationRoot, String userName) {
    log.debug("*** Getter.getUserIdFromName ***");
    String result = new String();
    Connection conn = Database.getCoreConnection(ApplicationRoot);
    try {
        CallableStatement callstmt = conn.prepareCall("call userGetIdByName(?)");
        log.debug("Gathering userGetIdByName ResultSet");
        callstmt.setString(1, userName);
        ResultSet resultSet = callstmt.executeQuery();
        log.debug("Opening Result Set from userGetIdByName");
        resultSet.next();
        result = resultSet.getString(1);
    } catch (SQLException e) {
        log.error("Could not execute query: " + e.toString());
        result = null;
    }
    Database.closeConnection(conn);
    log.debug("*** END getUserIdFromName ***");
    return result;
}

From source file:dbProcs.Getter.java

/**
 * @param ApplicationRoot The current running context of the application
 * @param moduleId Identifier of module//from w w  w.j  av  a2 s.c om
 * @return The db stored solution key value for the moduleId submitted
 */
public static String getModuleResult(String ApplicationRoot, String moduleId) {
    log.debug("*** Getter.getModuleResult ***");
    String moduleFound = null;
    Connection conn = Database.getCoreConnection(ApplicationRoot);
    try {
        CallableStatement callstmt = conn.prepareCall("call moduleGetResult(?)");
        log.debug("Gathering moduleGetResult ResultSet");
        callstmt.setString(1, moduleId);
        ResultSet moduleFind = callstmt.executeQuery();
        log.debug("Opening Result Set from moduleGetResult");
        moduleFind.next();
        log.debug("Module " + moduleFind.getString(1) + " Found");
        moduleFound = moduleFind.getString(2);
    } catch (Exception e) {
        log.error("Module did not exist: " + e.toString());
        moduleFound = null;
    }
    Database.closeConnection(conn);
    log.debug("*** END getModuleResult ***");
    return moduleFound;
}

From source file:dbProcs.Getter.java

/**
 * Used to present the progress of a class in a series of loading bars
 * @param applicationRoot The current running context of the application
 * @param classId The identifier of the class to use in lookup
 * @return A HTML representation of a class's progress in the application
 *//*from ww w.j av a2s. c  o  m*/
public static String getProgress(String applicationRoot, String classId) {
    log.debug("*** Getter.getProgress ***");

    String result = new String();
    Encoder encoder = ESAPI.encoder();
    Connection conn = Database.getCoreConnection(applicationRoot);
    try {
        log.debug("Preparing userProgress call");
        CallableStatement callstmnt = conn.prepareCall("call userProgress(?)");
        callstmnt.setString(1, classId);
        log.debug("Executing userProgress");
        ResultSet resultSet = callstmnt.executeQuery();
        int resultAmount = 0;
        while (resultSet.next()) //For each user in a class
        {
            resultAmount++;
            if (resultSet.getString(1) != null) {
                result += "<tr><td>" + encoder.encodeForHTML(resultSet.getString(1)) + //Output their progress
                        "</td><td><div style='background-color: #A878EF; heigth: 25px; width: "
                        + widthOfUnitBar * resultSet.getInt(2) + "px;'>" + "<font color='white'><strong>"
                        + resultSet.getInt(2);
                if (resultSet.getInt(2) > 6)
                    result += " Modules";
                result += "</strong></font></div></td></tr>";
            }
        }
        if (resultAmount > 0)
            result = "<table><tr><th>Player</th><th>Progress</th></tr>" + result + "</table>";
        else
            result = new String();
    } catch (SQLException e) {
        log.error("getProgress Failure: " + e.toString());
        result = null;
    }
    Database.closeConnection(conn);
    log.debug("*** END getProgress ***");
    return result;
}

From source file:dbProcs.Getter.java

/**
 * This method retrieves the i18n local key for a module's name.
 * @param applicationRoot Application Running Context
 * @param moduleId ID of the module to lookup
 * @return Locale key for the Module's Name.
 *//*from www.  j a v a 2  s  .c o  m*/
public static String getModuleNameLocaleKey(String applicationRoot, String moduleId) {
    log.debug("*** Getter.getModuleNameLocaleKey ***");
    String result = new String();
    Connection conn = Database.getCoreConnection(applicationRoot);
    try {
        CallableStatement callstmt = conn.prepareCall("call moduleGetNameLocale(?)");
        log.debug("Gathering moduleGetNameLocale ResultSet");
        callstmt.setString(1, moduleId);
        ResultSet resultSet = callstmt.executeQuery();
        log.debug("Opening Result Set from moduleGetNameLocale");
        resultSet.next();
        result = resultSet.getString(1);
    } catch (SQLException e) {
        log.error("Could not execute moduleGetNameLocale: " + e.toString());
        result = null;
    }
    Database.closeConnection(conn);
    log.debug("*** END getModuleNameLocaleKey ***");
    return result;
}

From source file:dbProcs.Getter.java

/**
 * Use to return the current progress of a class in JSON format with information like user name, score and completed modules
 * @param applicationRoot The current running context of the application
 * @param classId The identifier of the class to use in lookup
 * @return A JSON representation of a class's progress in the application
 *//*from w  ww. j ava 2  s . c  om*/
@SuppressWarnings("unchecked")
public static String getProgressJSON(String applicationRoot, String classId) {
    log.debug("*** Getter.getProgressJSON ***");

    String result = new String();
    Encoder encoder = ESAPI.encoder();
    Connection conn = Database.getCoreConnection(applicationRoot);
    try {
        log.debug("Preparing userProgress call");
        //Returns User's: Name, # of Completed modules and Score
        CallableStatement callstmnt = conn.prepareCall("call userProgress(?)");
        callstmnt.setString(1, classId);
        log.debug("Executing userProgress");
        ResultSet resultSet = callstmnt.executeQuery();
        JSONArray json = new JSONArray();
        JSONObject jsonInner = new JSONObject();
        int resultAmount = 0;
        while (resultSet.next()) //For each user in a class
        {
            resultAmount++;
            jsonInner = new JSONObject();
            if (resultSet.getString(1) != null) {
                jsonInner.put("userName", new String(encoder.encodeForHTML(resultSet.getString(1)))); //User Name
                jsonInner.put("progressBar", new Integer(resultSet.getInt(2) * widthOfUnitBar)); //Progress Bar Width
                jsonInner.put("score", new Integer(resultSet.getInt(3))); //Score
                log.debug("Adding: " + jsonInner.toString());
                json.add(jsonInner);
            }
        }
        if (resultAmount > 0)
            result = json.toString();
        else
            result = new String();
    } catch (SQLException e) {
        log.error("getProgressJSON Failure: " + e.toString());
        result = null;
    } catch (Exception e) {
        log.error("getProgressJSON Unexpected Failure: " + e.toString());
        result = null;
    }
    Database.closeConnection(conn);
    log.debug("*** END getProgressJSON ***");
    return result;
}

From source file:dbProcs.Getter.java

/**
 * Convert module hash to ID//from www.j  a  v  a2s. c o m
 * @param ApplicationRoot The current running context of the application
 * @param moduleHash The module hash to use for look up
 * @return The identifier of the module with the module hash of the moduleHash parameter
 */
public static String getModuleIdFromHash(String ApplicationRoot, String moduleHash) {
    log.debug("*** Getter.getModuleIdFromHash ***");
    log.debug("Getting ID from Hash: " + moduleHash);
    String result = new String();
    Connection conn = Database.getCoreConnection(ApplicationRoot);
    try {
        CallableStatement callstmt = conn.prepareCall("call moduleGetIdFromHash(?)");
        log.debug("Gathering moduleGetIdFromHash ResultSet");
        callstmt.setString(1, moduleHash);
        ResultSet resultSet = callstmt.executeQuery();
        log.debug("Opening Result Set from moduleGetIdFromHash");
        resultSet.next();
        result = resultSet.getString(1);
    } catch (SQLException e) {
        log.error("Could not execute query: " + e.toString());
        result = null;
    }
    Database.closeConnection(conn);
    log.debug("*** END getModuleIdFromHash ***");
    return result;
}

From source file:dbProcs.Getter.java

/**
 * Used to return a module cheat sheet/* w  w  w  . j  av  a2  s  .  com*/
 * @param ApplicationRoot The current running context of the application
 * @param moduleId The identifier of the module to return the cheat sheet for
 * @param lang The Locale the user has enabled
 * @return String[] containing {ModuleName, CheatSheetSolution}
 */
public static String[] getModuleSolution(String ApplicationRoot, String moduleId, Locale lang) {
    log.debug("*** Getter.getModuleSolution ***");
    String[] result = new String[2];
    Connection conn = Database.getCoreConnection(ApplicationRoot);
    //Getting Translations
    ResourceBundle bundle = ResourceBundle.getBundle("i18n.cheatsheets.solutions", lang);
    try {
        CallableStatement callstmt = conn.prepareCall("call cheatSheetGetSolution(?)");
        log.debug("Gathering cheatSheetGetSolution ResultSet");
        callstmt.setString(1, moduleId);
        ResultSet resultSet = callstmt.executeQuery();
        log.debug("Opening Result Set from cheatSheetGetSolution");
        resultSet.next();
        result[0] = resultSet.getString(1);
        result[1] = bundle.getString(resultSet.getString(2));

    } catch (SQLException e) {
        log.error("Could not execute query: " + e.toString());
        result = null;
    }
    Database.closeConnection(conn);
    log.debug("*** END getModuleSolution ***");
    return result;
}