今天很郁悶 ,被一個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());
附件是這段代碼中用到的類。