SHARE
TWEET

getPhrases

a guest Dec 13th, 2016 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  public static ArrayList<String> getPhrases(int gameId) {
  2.  
  3.         String database = "catchphrase";
  4.         PreparedStatement ps = null;
  5.         String sql = null;
  6.         Connection conn = null;
  7.  
  8.         try {
  9.  
  10.             String propFileName = "spring.data-access";
  11.             ResourceBundle rb = ResourceBundle.getBundle(propFileName);
  12.             String dbUserName = rb.getString("jdbc.username");
  13.             String dbPassword = rb.getString("jdbc.password");
  14.             System.out.println("BJM-Set the database to " + database);
  15.  
  16.             DatabaseConnection newConnection = new DatabaseConnection(database, dbUserName, dbPassword);
  17.             conn = ConnectionUtils.getConnection(newConnection);
  18.  
  19.             sql = "SELECT category FROM gamedetails WHERE gameId = ?;";
  20.  
  21.             ps = conn.prepareStatement(sql);
  22.             ps.setInt(1, gameId);
  23.  
  24.             ResultSet rs = ps.executeQuery();
  25.  
  26.             rs.next();
  27.  
  28.             String category = rs.getString("category");
  29.  
  30.             sql = "SELECT CodeTypeId FROM codetype WHERE englishDescription = ?";
  31.  
  32.             ps = conn.prepareStatement(sql);
  33.             ps.setString(1, category);
  34.  
  35.             rs = ps.executeQuery();
  36.  
  37.             rs.next();
  38.  
  39.             int codeTypeId = rs.getInt("CodeTypeId");
  40.  
  41.             sql = "SELECT englishDescription FROM codevalue WHERE codeTypeId = ?";
  42.  
  43.             ps = conn.prepareStatement(sql);
  44.             ps.setInt(1, codeTypeId);
  45.  
  46.             rs = ps.executeQuery();
  47.  
  48.             ArrayList<String> phrases = new ArrayList<String>();
  49.  
  50.             while (rs.next()) {
  51.                 phrases.add(rs.getString("englishDescription"));
  52.             }
  53.  
  54.             return phrases;
  55.  
  56.         } catch (Exception e) {
  57.             String errorMessage = e.getMessage();
  58.             e.printStackTrace();
  59.             return null;
  60.         } finally {
  61.             DbUtils.close(ps, conn);
  62.         }
  63.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top