Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. public List<Person> getPersons() {
  2.  
  3. List<Person> personList = new ArrayList<>();
  4. connection = null;
  5. rs = null;
  6. try {
  7. Class.forName("org.sqlite.JDBC");
  8. connection = DriverManager.getConnection("jdbc:sqlite:D:/base/testDB.db");
  9. Statement statement = connection.createStatement();
  10. statement.setQueryTimeout(30);
  11. rs = statement.executeQuery("SELECT * FROM GoodInfo");
  12. while (rs.next()) {
  13. Person person = new Person();
  14. person.setGood_id(rs.getInt("good_id"));
  15. person.setGood_name(rs.getString("good_name"));
  16. person.setGood_code(rs.getInt("good_code"));
  17. person.setCategory_id(rs.getInt("category_id"));
  18. personList.add(person);
  19.  
  20. }
  21. } catch (SQLException e) {
  22. e.printStackTrace();
  23. } catch (ClassNotFoundException e) {
  24. e.printStackTrace();
  25. } finally {
  26. try {
  27. if (connection != null) {
  28. connection.close();
  29. }
  30. } catch (SQLException e) {
  31. e.printStackTrace();
  32. }
  33. }
  34. return personList;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement