java中调用oracle中的函数出错??
韩顺平的java中调用oracle的函数出现了下面的错误,望大家给与指导,谢谢!!
import java.sql.*;
public class TestOracle4 {
/**
* @param args
*/
public static void main(String[] args) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection ct=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl","scott","tiger");
CallableStatement cs =ct.prepareCall("{select fun1('SCOTT') from dual}");
cs.execute();
cs.getInt(1);
cs.close();
ct.close();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
bug:
java.sql.SQLException: 出现不支持的 SQL92 标记: 7: select
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:916)
at oracle.jdbc.driver.OracleSql.handleToken(OracleSql.java:152)
at oracle.jdbc.driver.OracleSql.handleODBC(OracleSql.java:112)
at oracle.jdbc.driver.OracleSql.parse(OracleSql.java:64)
at oracle.jdbc.driver.OracleConnection.nativeSQL(OracleConnection.java:1086)
at oracle.jdbc.driver.OracleStatement.expandSqlEscapes(OracleStatement.java:5703)
at oracle.jdbc.driver.OracleStatement.parseSqlKind(OracleStatement.java:5692)
at oracle.jdbc.driver.OraclePreparedStatement.<init>(OraclePreparedStatement.java:238)
at oracle.jdbc.driver.OracleCallableStatement.<init>(OracleCallableStatement.java:111)
at oracle.jdbc.driver.OracleCallableStatement.<init>(OracleCallableStatement.java:95)
at oracle.jdbc.driver.OracleConnection.privatePrepareCall(OracleConnection.java:1055)
at oracle.jdbc.driver.OracleConnection.prepareCall(OracleConnection.java:893)
at TestOracle4.main(TestOracle4.java:11)
[解决办法]
既然采用select哑表的方式就不需要用CallableStatement了吧,直接用普通查询的Statement解决,要用CallableStatement就直接call函数并指定参数。