Missing IN or OUT parameter at index:: 1 error in Java, Oracle

元气小坏坏 提交于 2019-12-10 03:45:26

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/27342697/missing-in-or-out-parameter-at-index-1-error-in-java-oracle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!