Method of invoking stored procedures in Java (iii) stored procedures for deleting data

Source: Internet
Author: User

Iii. stored procedures for deleting data

------------------Stored Procedures--------------------------

drop table 学生基本信息表
create table 学生基本信息表
(
StuID int primary key,
StuName varchar(10),
StuAddress varchar(20)
)
insert into 学生基本信息表 values(1,'三毛','wuhan')
insert into 学生基本信息表 values(2,'三毛','wuhan')
create table 学生成绩表
(
StuID int,
Chinese int,
PyhSics int
foreign key(StuID) references 学生基本信息表(StuID)
on delete cascade
on update cascade
)
insert into 学生成绩表 values(1,99,100)
insert into 学生成绩表 values(2,99,100)

--Create a stored procedure
CREATE PROCEDURE Delepro
@StuID int
As
Delete from Student basic information table where stuid= @StuID
--Finish creating Bi
EXEC delepro 1-Execute stored procedure
-Create stored procedure
CREATE PROCEDURE Selepro
as
Select * from Student basic table
--Create complete
EX EC selepro-Execute stored procedure
------------------call in Java----------------
Import java.sql.*;
public class Proceduretest
{
public static void Main (String args[]) throws Exception
{
//load driver
Drivermanager.regist Erdriver (New Sun.jdbc.odbc.JdbcOdbcDriver ());
//Get connection
Connection conn=drivermanager.getconnection ("Jdbc:odbc:mydata", "sa", "");

//创建存储过程的对象
CallableStatement c=conn.divpareCall("{call delePro(?)}");

c.setInt(1,1);

c.execute();

c=conn.divpareCall("{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();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.