Hi I coded a Library Management System in JSF 2.2 with using Netbeans 8.0.2 and Oracle 11g Express Edition. I have several pages named Books, Borrowers etc. and some tables named same in database. My problem is this: in Borrowers screen book ids are displayed. But I want to reach book's titles that have same id. Here is my code.
public List<Borrower> getBorrowers()throws ClassNotFoundException,SQLException, InstantiationException, IllegalAccessException{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","Alparslan-PC","123456");
ps=con.prepareStatement("SELECT * FROM BORROWER");
BookidPs = con.prepareStatement("SELECT TITLE FROM BOOK AND BORROWER WHERE ISBN=?");
ResultSet rs=ps.executeQuery();
ResultSet Rs2=BookidPs.executeQuery();
List<Borrower> liste = new ArrayList<Borrower>();
while(rs.next()){
Borrower borrow = new Borrower();
borrow.setId(rs.getBigDecimal("ID"));
borrow.setName(rs.getString("NAME"));
borrow.setSurname(rs.getString("SURNAME"));
borrow.setAddress(rs.getString("ADDRESS"));
borrow.setPhonenumber(rs.getString("PHONENUMBER"));
borrow.setBorrowdate(rs.getString("BORROWDATE"));
//book.setIsbn(rs.getString("BOOKID"))
borrow.setBookid(Rs2.getString("BOOKID"));
//borrow.setBookid(((Book) rs.getObject("BOOKID")).getIsbn());
liste.add(borrow);
}
System.out.print(liste);
return liste;
}
if line 22 changed with borrow.setBookid(rs.getString("BOOKID")); The bookids are shown. I wrote another query named BookidPs. if I run this program I get Missing IN or OUT parameter at index:: 1 error. If you help I will appretiate. Thanks
The "Missing IN or OUT parameter" in the error message is for the ?
in the query:
SELECT TITLE FROM BOOK AND BORROWER WHERE ISBN=?
You didn't supply a value for it. Try like this:
BookidPs = con.prepareStatement("SELECT TITLE FROM BOOK AND BORROWER WHERE ISBN=?");
BookidPs.setString(1, theIsbn);
The query needs an ISBN parameter, but I don't see where you have such variable in your code.
To use this query, you need to provide the missing parameter. In fact, it seems this second query is not useful for you at all. Given the code, I don't see why you want to use this query instead of getting the value from rs
.
But actually, even with that parameter filled, the query is invalid SQL.
I think you probably want just one query, a JOIN. Your second query seems to try to select the TITLE from the BOOK table. So maybe you want this query, without parameters:
SELECT * FROM BORROWER JOIN BOOK ON BORROWER.BOOKID = BOOK.BOOKID
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With