@Override public void delete(Author author) throws SQLException { String[] tmp = author.parseAuthor(); String query = "DELETE FROM LIBRARY.AUTHORS WHERE NAME='" + tmp[0] + "' AND COUNTRY='" + tmp[1] + "';"; PreparedStatement ps = con.prepareStatement(query); ps.executeUpdate(); }
@Override public void insert(Author author) throws SQLException { String query = "INSERT INTO LIBRARY.AUTHORS (NAME, COUNTRY) VALUES (?,?);"; PreparedStatement ps = con.prepareStatement(query); ps.setString(1, author.parseAuthor()[0]); ps.setString(2, author.parseAuthor()[1]); ps.executeUpdate(); }
@Override public List<Author> get(String field) throws SQLException { String query = "SELECT * FROM LIBRARY.AUTHORS WHERE ID='%" + field + "%' OR NAME LIKE '%" + field + "%' OR COUNTRY LIKE '%" + field + "%';"; PreparedStatement ps = con.prepareStatement(query); ResultSet resSet = ps.executeQuery(); List<Author> authors = new LinkedList<>(); while (resSet.next()) { Author author = new Author(); authors.add(author.parseAuthor(resSet)); } return authors; }