ORA-00904:标识符无效,preparedstatement


今天很郁闷 ,被一个java.sql.SQLException:"CLIENTTYPE" ORA-00904:标识符无效错误给折腾得不行了。

一直找错,执行的sql扔到pl/sql里没问题,但是运行代码就出错,那个汗颜啊。最后看到网上有同样经历的,顿悟了一下,配置。。。没改过来,java中和ps/sql中连接了不同的库。mark,一下以后小心。

另外,用preprestatement执行的sql看不见也非常郁闷。找到一个包可以打印出,不过对于spring中使用的dbcp连接池不太好用,不过测试用还可以。

 

Connection con = DriverManager.getConnection(url);
DebugLevel debug = DebugLevel.ON;
String sql = "SELECT name,rate FROM EmployeeTable WHERE rate > ?";
//Use a factory instead of Connection to get a PreparedStatement.
//PreparedStatement ps = con.prepareStatement(sql);
PreparedStatement ps = StatementFactory.getStatement(con,sql,debug);
ps.setInt(1,25);
//If ps is a DebuggableStatement, you see the statement,
//otherwise, an object identifier is displayed
System.out.println(" debuggable statement= " + ps.toString());

附件是这段代码中用到的类。 

点击我下载


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM