public String getBookNames(int bookid2)throws ClassNotFoundException,SQLException, InstantiationException, IllegalAccessException{ Book book2 = new Book(); book2.setIsbn(bookid2); String str = null; Class.forName("oracle.jdbc.driver.OracleDriver"); con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","Alparslan-PC","123456"); BookidPs = con.prepareStatement("SELECT DISTINCT BOOK.TITLE FROM BOOK " + "JOIN BORROWER ON BOOK.ISBN= BORROWER.BOOKID " + "WHERE Nvl (BOOK.ISBN,"+bookid2+")="+bookid2); ResultSet Rs2 = BookidPs.executeQuery(); while(Rs2.next()){ str = Rs2.getString("TITLE"); } System.out.print(str); return str; }
public Book findBook(int isbn) throws SQLException, ClassNotFoundException{ Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection(url, user, password); String find = "SELECT * from boo WHERE isbn = ?"; PreparedStatement stt = con.prepareStatement(find); stt.setInt(1, isbn); ResultSet rs = stt.executeQuery(); Book b2 = new Book(); while (rs.next()){ b2.setIsbn(rs.getInt("isbn"); b2.setTitle(rs.getString("title"); } // If more than one entry (row) is returned from the query, // b2 will only represent the last one. // Close these in reverse order of creation rs.close(); stt.close(); con.close(); return b2; }
public static void main(String[] args) { Class myClass2 = null; try { myClass2 = Class.forName("Book"); } catch (ClassNotFoundException e) { System.out.println("Error: " + e); } if (myClass2 != null) { try { //Creating an instance of the Book class Book book1 = (Book) myClass2.newInstance(); book1.setAuthor("Khan"); System.out.println(book1.getAuthor()); book1.setTitle("Second Book"); book1.setIsbn("kh_s_b"); book1.printBookDetails(); } catch (IllegalAccessException e1) { System.out.println("Error1 " + e1); } catch (InstantiationException e2) { System.out.println("Error2 " + e2); } } }//main method ends here.
// create manager and two example books SimpleBookManager manager = new SimpleBookManager(); Book harryPotter1 = manager.createBook(); Book harryPotter2 = manager.createBook(); harryPotter1.setAuthor("JK Rowling"); harryPotter1.setCourse("Harry Potter Kunskap"); harryPotter1.setPrice(199); harryPotter1.setTitle("Harry Potter and the philosifer Stone"); harryPotter1.setIsbn("9780590353403"); harryPotter2.setAuthor("JK Rowling"); harryPotter2.setCourse("Harry Potter Kunskap"); harryPotter2.setPrice(299); harryPotter2.setTitle("Harry Potter and snake"); harryPotter2.setIsbn("0439064872"); // let's use an intent to parcel the manager to Intent intent = new Intent(); intent.putExtra("extra_book_manager", manager); // read the parcelled manager back from the intent SimpleBookManager parcelledManager = intent.getParcelableExtra("extra_book_manager");
isbn.setIsbn(scan.nextInt());