1
        Statement stmt = con.createStatement();

        String pubBooks = "select title_name " +
                "from publisher, title " +
                "where pub_name = ? " +
                "and publisher.pub_no = title.pub_no " +
                "order by title_name";
        ResultSet rS = stmt.executeQuery(pubBooks);
        stmt.close();
        String pubss = "Irwin";
        PreparedStatement pStmt = 
            con.prepareStatement(pubBooks);
        pStmt.setString(1, pubss);
        pStmt.executeUpdate();

Hey, I'm trying to use JDBC to query my database to the the list of book titles produced by that publisher however I run into the error java.sql.SQLException: ORA-01008: not all variables bound. I've been trying everything that I can think of but I am just not quite sure what to do at this point.

2 Answers 2

3

You were close with trying PreparedStatement, except that you just called the wrong "execute" method. Use the executeQuery() method to return your ResultSet.

PreparedStatement pStmt = 
con.prepareStatement(pubBooks);
pStmt.setString(1, pubss);
ResultSet rS = pStmt.executeQuery();
Sign up to request clarification or add additional context in comments.

1 Comment

You don't need your Statement at all, just your PreparedStatement.
1

Statement can't be used when supplying parameters to the query, use PreparedStatement. You may have to revise your code as below:

    String pubBooks = "select title_name " +
            "from publisher, title " +
            "where pub_name = ? " +
            "and publisher.pub_no = title.pub_no " +
            "order by title_name";

    String pubss = "Irwin";

    PreparedStatement pStmt =  con.prepareStatement(pubBooks);
    pStmt.setString(1, pubss);
    ResultSet rS = pStmt.executeQuery();

    //TODO: code to use resultset rS

    rS.close();
    pstmt.close();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.