????D??????????洢????
?????????洢?????
????create procedure ModPro
????@StuID int??
????@StuName varchar(10)
????as
????update ???????????? set StuName=@StuName where StuID=@StuID
???????д洢?????
????exec ModPro 2??'???'
????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"??"");
//?????洢????????
CallableStatement c=conn.prepareCall("{call ModPro(????)}");
c.setInt(1??2);
c.setString(2??"???");
c.execute();
c=conn.prepareCall("{call selePro}");
ResultSet rs=c.executeQuery();
while(rs.next())
{
String Stu=rs.getString("StuID");
String name=rs.getString("StuName");
String add=rs.getString("StuAddress");
System.out.println ("???:"+" "+"????:"+" "+"???");
System.out.println (Stu+" "+name+" "+add);
}
c.close();
}
}
????E??????????洢????(??????)
?????洢?????
????create procedure FindCusts
????@cust varchar(10)
????as
????select customerid from orders where customerid
????like '%'+@cust+'%'
???????У?
????execute FindCusts 'alfki'
??????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"??"");
//?????洢????????
CallableStatement c=conn.prepareCall("{call FindCusts(?)}");
c.setString(1??"Tom");
ResultSet rs=c.executeQuery();
while(rs.next())
{
String cust=rs.getString("customerid");
System.out.println (cust);
}
c.close();
}
}
????F??????????洢????
?????洢?????
????create procedure InsertPro
????@StuID int??
????@StuName varchar(10)??
????@StuAddress varchar(20)
????as
????insert into ???????????? values(@StuID??@StuName??@StuAddress)
????????洢?????
????exec InsertPro 5??'555'??'555'
??????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"??"");
//?????洢????????
CallableStatement c=conn.prepareCall("{call InsertPro(???????)}");
c.setInt(1??6);
c.setString(2??"Liu");
c.setString(3??"wuhan");
c.execute();
c=conn.prepareCall("{call selePro}");
ResultSet rs=c.executeQuery();
while(rs.next())
{
String stuid=rs.getString("StuID");
String name=rs.getString("StuName");
String address=rs.getString("StuAddress");
System.out.println (stuid+" "+name+" "+address);
}
c.close();
}
}
????G????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.prepareCall("{call OOP}");
ResultSet rs=c.executeQuery();
while(rs.next())
{
String chinese=rs.getString("Chinese");
System.out.println (chinese);
}
conn.close();
}
}