Search code examples
sqloraclevariablessql-likesetstring

SQL with variable in LIKE statement: Invalid column Index


I'm using Oracle.

PreparedStatement pstmt = con.prepareStatement("SELECT * FROM BookLoanInfo WHERE title LIKE '%?%' ORDER BY bid");
ResultSet rs;
String bookstring = scan.nextLine();
try{
    pstmt.clearParameters();
    pstmt.setString(1, bookstring);
    rs = pstmt.executeQuery();

The actual problem seems to be with either the setString or how I have typed the query.

This however gives Invalid Column Index.


Solution

  • You'll need to specify the wildcards as part of your setString statement.

    Wildcard in Prepared Statement