七、在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();
}
}