简体   繁体   English

Java JDBC调用Oracle 10函数“无效标识符”

[英]Java JDBC call to Oracle 10 function “invalid identifier”

I'm having a problem I haven't encountered before: there is a stored function in a database: CC_PROC, which takes two date entries and returns a table. 我遇到了一个以前从未遇到过的问题:数据库中有一个存储函数:CC_PROC,它需要两个日期条目并返回一个表。 In other words, to call it, you type: 换句话说,要键入它,请键入:

SELECT * FROM (TABLE( CC_PROC( DATE '2012-01-01', DATE '2012-01-15')));

This seems to work perfectly in SQLPlus and NetBeans, and the above line has been apparently been in use for some time. 这似乎在SQLPlus和NetBeans中完美地工作,并且上面的代码行显然已经使用了一段时间。

Anyway, when calling it from java using a prepared statement, I get: "CC_PROC": invalid identifier on the executeQuery call. 无论如何,当使用准备好的语句从Java调用它时,我得到:“ CC_PROC”:executeQuery调用上的无效标识符。

This is with: 这是与:

PreparedStatement preparedStatement = 
     connection.prepareStatement("SELECT * FROM (TABLE ( CC_PROC( ? , ? )))");
preparedStatement.setDate(1,firstDate);
preparedStatement.setDate(2,secondDate);
resultSet = preparedStatement.executeQuery();

I feel like maybe this is obvious and my limited experience using JDBC directly instead of Hibernate is throwing me. 我觉得这也许很明显,而我直接使用JDBC而不是Hibernate的有限经验使我感到困惑。 I'd like to not have to re-code the contents of CC_PROC in java business logic. 我不想在Java业务逻辑中重新编码CC_PROC的内容。 Any ideas? 有任何想法吗?

Thanks! 谢谢!

Aha, found the answer: 啊哈,找到答案了:

The oracle user was SALESOWN, so the fix was: oracle用户是SALESOWN,因此解决方法是:

PreparedStatement preparedStatement = connection.prepareStatement(
        "SELECT * FROM (TABLE ( SALESOWN.CC_PROC( ? , ? )))");

Yikes. 让人惊讶。 I don't want to admit the amount of time it took to figure that out. 我不想承认花费很多时间来解决这个问题。

Apparently SQLPlus and NetBeans do attempt to help out a little... 显然,SQLPlus和NetBeans确实尝试提供一些帮助。

Thanks for the help guys! 感谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM