Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static ArrayList<String> getPhrases(int gameId) {
- String database = "catchphrase";
- PreparedStatement ps = null;
- String sql = null;
- Connection conn = null;
- try {
- String propFileName = "spring.data-access";
- ResourceBundle rb = ResourceBundle.getBundle(propFileName);
- String dbUserName = rb.getString("jdbc.username");
- String dbPassword = rb.getString("jdbc.password");
- System.out.println("BJM-Set the database to " + database);
- DatabaseConnection newConnection = new DatabaseConnection(database, dbUserName, dbPassword);
- conn = ConnectionUtils.getConnection(newConnection);
- sql = "SELECT category FROM gamedetails WHERE gameId = ?;";
- ps = conn.prepareStatement(sql);
- ps.setInt(1, gameId);
- ResultSet rs = ps.executeQuery();
- rs.next();
- String category = rs.getString("category");
- sql = "SELECT CodeTypeId FROM codetype WHERE englishDescription = ?";
- ps = conn.prepareStatement(sql);
- ps.setString(1, category);
- rs = ps.executeQuery();
- rs.next();
- int codeTypeId = rs.getInt("CodeTypeId");
- sql = "SELECT englishDescription FROM codevalue WHERE codeTypeId = ?";
- ps = conn.prepareStatement(sql);
- ps.setInt(1, codeTypeId);
- rs = ps.executeQuery();
- ArrayList<String> phrases = new ArrayList<String>();
- while (rs.next()) {
- phrases.add(rs.getString("englishDescription"));
- }
- return phrases;
- } catch (Exception e) {
- String errorMessage = e.getMessage();
- e.printStackTrace();
- return null;
- } finally {
- DbUtils.close(ps, conn);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement