0

I've got a weird problem in Oracle query running from Java with Oracle 11g. The same query worked good with Oracle 10g. tool_availability is a view.

final String SELECT_SQL = "select * " +
            "from tool_availability " +
            "where tool_code = ? " +
            "and tool_number = ? " +
            "and unit = ? " +
            "and part_id = ? ";

ps = con.prepareStatement(SELECT_SQL);
ps.setFetchDirection(ResultSet.FETCH_FORWARD);
ps.setFetchSize(1);
ps.setString(1, tool_code);
ps.setString(2, tool_number);
ps.setString(3, unit);
ps.setString(4, part_id);
rs = ps.executeQuery();

The query has space before and after '?' mark. The same query is not working with 11g and I'm getting below error:

java.sql.SQLException: ORA-01036: illegal variable name/number  

If I remove the space before and after '?' mark. The same query is working with 11g.

Could anybody give some insight what could be the problem?

1
  • My guess is it is the difference in JDBC. Are you importing the ORACLE JDBC driver or the generic one? Are you importing a different driver based upon Oracle version? I would look there. Commented Dec 19, 2014 at 6:29

1 Answer 1

1

You have to avoid to set String in preparedstatement.

In preparedStatement , you need to set actual type.

ps.setString(1, tool_code);
ps.setInt(2, tool_number);
ps.setInt(3, unit);
ps.setString(4, part_id);

like that you have to do

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your response. The datatype for all columns are VARCHAR2.

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.