Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static ArrayList<CodeType> getCodeTypes() {
- ArrayList<CodeType> categories = new ArrayList();
- String database = "catchphrase";
- PreparedStatement ps = null;
- String sql = null;
- Connection conn = null;
- try {
- //connect to database
- 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 * FROM `CodeType` order by codeTypeId";
- ps = conn.prepareStatement(sql);
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- // It is possible to get the columns via name
- // also possible to get the columns via the column number
- // which starts at 1
- // e.g. resultSet.getString(2);
- CodeType category = new CodeType();
- category.setCodeTypeId(rs.getInt("codeTypeId"));
- category.setEnglishDescription(rs.getString("englishDescription"));
- category.setFrenchDescription(rs.getString("frenchDescription"));
- System.out.println("Found code type=" + category);
- categories.add(category);
- }
- } catch (Exception e) {
- String errorMessage = e.getMessage();
- e.printStackTrace();
- } finally {
- DbUtils.close(ps, conn);
- }
- return categories;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement