Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab8.zad2;
- import java.sql.*;
- import static java.lang.System.out;
- public class DB {
- public static ResultSet searchAuthor(String authorsBooks, String parametr) throws SQLException {
- ResultSet rs;
- Connection c = DriverManager.getConnection("jdbc:mysql://mysql.agh.edu.pl/amaczyn", "amaczyn", "gt3W6btDC0926rd7");
- if(parametr.equals("author")) {
- PreparedStatement stmt = c.prepareStatement("SELECT * FROM books WHERE author LIKE ? ;");
- stmt.setString(1, "%" +authorsBooks +"%");
- rs = stmt.executeQuery();
- return rs;
- }
- else {
- PreparedStatement stmt = c.prepareStatement("SELECT * FROM books WHERE isbn=? ;");
- stmt.setString(1, authorsBooks);
- rs = stmt.executeQuery();
- return rs;
- }
- }
- public static boolean insertBook(String isbn, String title, String author, String year) throws SQLException {
- Connection c = DriverManager.getConnection("jdbc:mysql://mysql.agh.edu.pl/amaczyn", "amaczyn", "gt3W6btDC0926rd7");
- PreparedStatement statement = c.prepareStatement("INSERT INTO books VALUES (?, ?, ?, ?)");
- statement.setString(1, isbn);
- statement.setString(2, title);
- statement.setString(3, author);
- statement.setString(4, year);
- statement.executeUpdate();
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement