JAVA中对存储过程的调用方法(七) 创建、并在JAVA中直接调用存储过程
时间:2011-07-03 本站整理
七、在JAVA中创建存储过程 并且在JAVA中直接调用
import java.sql.*;
public class ProcedureTest
{
public static void main(String args[]) throws Exception
{
//加载驱动
DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
//获得连接
Connection conn=DriverManager.getConnection("jdbc:odbc:mydata","sa","");
Statement stmt=conn.createStatement();
//在JAVA中创建存储过程
stmt.executeUpdate("create procedure OOP as select * from 学生成绩表");
CallableStatement c=conn.divpareCall("{call OOP}");
ResultSet rs=c.executeQuery();
while(rs.next())
{
String chinese=rs.getString("Chinese");
System.out.println (chinese);
}
conn.close();
}
}
|