Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<Person> getPersons() {
- List<Person> personList = new ArrayList<>();
- connection = null;
- rs = null;
- try {
- Class.forName("org.sqlite.JDBC");
- connection = DriverManager.getConnection("jdbc:sqlite:D:/base/testDB.db");
- Statement statement = connection.createStatement();
- statement.setQueryTimeout(30);
- rs = statement.executeQuery("SELECT * FROM GoodInfo");
- while (rs.next()) {
- Person person = new Person();
- person.setGood_id(rs.getInt("good_id"));
- person.setGood_name(rs.getString("good_name"));
- person.setGood_code(rs.getInt("good_code"));
- person.setCategory_id(rs.getInt("category_id"));
- personList.add(person);
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } finally {
- try {
- if (connection != null) {
- connection.close();
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return personList;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement