java程序去调用oracle的存储过程时出错
//演示java程序去调用oracle的存储过程
package uncle.crazy;
import java.sql.*;
public class TestOracePro {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
//1.加载驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
//2.得到连接
Connection ct=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:MLDN","scott","tiger");
//3.创建CallableStatement
CallableStatement cs=ct.prepareCall("{call sp_pr4(?,?)}");
//4.给?赋值
cs.setString(1,"SMITH");
cs.setInt(2,10);
//5.执行
cs.execute();
//关闭
cs.close();
ct.close();
}
catch(Exception e) {
e.printStackTrace();
}
}
}
注明:已经在plsql中建立了存储过程sp_pr4
------解决方案--------------------报什么错,不要让我们猜测
------解决方案--------------------报错如下:
java.sql.SQLException:
ORA-06550: line 1, column 7:
PLS-00201: identifier 'SP_PR4' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:124)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:304)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:271)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:622)
at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:179)
at oracle.jdbc.driver.T4CCallableStatement.execute_for_rows(T4CCallableStatement.java:782)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1027)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2887)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:2978)
at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4102)
at uncle.crazy.TestOracePro.main(TestOracePro.java:23)
------解决方案--------------------你看,错误都报出来了,你的存储过程没有什声明啊!
你确定DB中没有问题,贴出来瞧下吧
------解决方案--------------------把procedure编译通过了 再在java中调用
------解决方案--------------------java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00201: identifier 'SP_PR4' must be declared
ORA-06550: line 1, column 7:
已经很明显的错误了!
你的SP_PR4这个存储过程编译有错误!
------解决方案--------------------存储过程是编译过了的,也没有错误
------解决方案----------------------存储过程如下,编译没错误
create or replace procedure sp_pr4(spName varchar2,newsal number) is
begin
--执行部分,根据用户名去修改工资
update scott.emp set sal=newSal where ename=spName;
end;
/
------解决方案--------------------java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00201: identifier 'SP_PR4' must be declared
ORA-06550: line 1, column 7:
"127.0.0.1:1521:MLDN","scott","tiger"
上面的代码清晰无误的表达了: