java中的代码:
----------------------------------------------------------------------------------
import java.sql.*;
import java.sql.Types;public class TestProcedure {
Connection conn = null;
CallableStatement callStmt = null;
public static void main(String[] args) {
TestProcedure tp = new TestProcedure();
tp.connect();
tp.procExec();
tp.closeConnect();
}
private void connect() {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("获取驱动成功!");
} catch (ClassNotFoundException e) {
System.out.println("创建数据库服务器驱动失败!");
e.printStackTrace();
}
try {
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:myoracle", "scott", "tiger");
System.out.println("数据库连接成功!");
} catch (SQLException e) {
System.out.println("连接数据库失败,请联系管理员!");
e.printStackTrace();
this.closeConnect();
}
}
//关闭,可以略过!
private void closeConnect() {
if (null != this.conn) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
this.conn = null;
}
if (null != this.callStmt) {
try {
this.callStmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
this.callStmt = null;
}
}
//执行
private void procExec() {
/*创建 CallableStatement 对象*/ try {
this.callStmt = conn.prepareCall("{call ps_pro3(?, ?)}");
System.out.println("创建 CallableStatement 对象成功!");
} catch (SQLException e) {
e.printStackTrace();
this.closeConnect();
}
/*设定指定参数*/ try {
this.callStmt.setString(1, "SMITH");
System.out.println("将第一个参数设置为给定 Java String 成功!");
this.callStmt.setInt(2, 6);
System.out.println("将第二个参数设置为给定 Java Int 成功!");
} catch (SQLException e) {
e.printStackTrace();
this.closeConnect();
}
try {
System.out.println("正在执行execute...");//程序只能执行到这里呢!下面的callStmt.execute();为什么执行通呢?并且不报错!
this.callStmt.execute();
//当然这条语句执行不到的!
System.out.println("执行成功了!!!");
} catch (SQLException e) {
e.printStackTrace();
this.closeConnect();
}
}
}
*********************************************************************************************
oracle中pro_name的代码:
-----------------------------------------------------------------------------------
create procedure pro_name(n_name varchar2, n_sal number) is
Begin
Update emp set sal=n_sal where ename=n_name;
end;
/**********************************************************************************
版本:oracle10g
java中的classes12.jar已经引入了!在oracle中执行:
SQL>exec pro_name('SMITH', 10000);是没有问题的,sal可以被更改!但是在java中执行时都没有错误,就是执行callStmt.execute();这句的时候没有反应!!哪个出问题了?
刚刚接触oracle和java,麻烦哪位朋友帮解决下,万分感谢!oraclejavaoracle10g存储
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货