Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static ArrayList<Book> bookList;
- public static void getBooks() throws SQLException {
- ArrayList<Book> list=new ArrayList<Book>();
- con = DriverManager.getConnection("jdbc:sqlite://"+dbFileLocation);
- stmt = con.createStatement();
- rs = stmt.executeQuery("SELECT * FROM books");
- while (rs.next()) {
- list.add(new Book(rs.getInt("BookId"),
- rs.getString("Name"),
- rs.getInt("Year"),
- rs.getInt("AuthorId"),
- rs.getBoolean("CheckedOut")));
- }
- bookList=list;
- }
- public static void insertBook(String name, int authorId, int year) {
- try {
- con = DriverManager.getConnection("jdbc:sqlite://"+dbFileLocation);
- PreparedStatement stmt=con.prepareStatement("INSERT INTO books(Name, AuthorId, Year) VALUES (?,?,?)");
- stmt.setString(1, name);
- stmt.setInt(2, authorId);
- stmt.setInt(3, year);
- stmt.executeUpdate();
- getBooks();
- }catch (SQLException e) {
- e.printStackTrace();
- }finally {
- try {
- stmt.close();
- con.close();
- }catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement