myEclipse,javabean里利用存储过程删除记录出问题.
问题说明:调用查旬方法selectquery()或添加方法insertquery(),都可以成功.
当调用删除方法deletequery()时,没有提示出错,但数据库里却没有删除掉.
不懂是怎么回事,调了好久了,希望高人指点,非常感谢!
数据库名:info
表名:Cinfo
表字段:id,name
表内容:102,tt
103,yy
删除记录的存储过程(利用生成向导做的,然后改成一个参数):
CREATE PROCEDURE [delete_Cinfo]
@id_1 [char]
AS DELETE [info].[dbo].[Cinfo]
WHERE
( [id] = @id_1 )
GO
查找记录的存储过程
CREATE PROCEDURE [select_Cinfo]
@id_1 [char](10)
AS select * from Cinfo
where id=@id_1
GO
javabean里的代码:
package com.operation.bean;
import java.sql.*;
public class sqloperation {
private String id;
private String name;
String url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=info ";
String user= "sa ";
String password= "sa ";
ResultSet rs=null;
CallableStatement st=null;
Connection conn=null;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
//调用存储过程执行删除记录操作(失败),当调用该方法的时候没有提示出错,
//但打开数据库并没有删掉103这条记录.
public void deletequery()throws Exception
{
st=conn.prepareCall( "{call delete_Cinfo(?)} ");
st.setString(1,103);
st.executeUpdate();
//st.execute();尝试用这句也不行.
st.close();
conn.close();
}
//调用存储过程执行查找记录操作(成功)
public void selectquery()throws Exception
{
st=conn.prepareCall( "{call select_Cinfo(?)} ");
st.setString(1, "102 ");
rs=st.executeQuery();
}
//调用存储过程执行添加记录操作(成功)
public void insertquery()throws Exception
{
st=conn.prepareCall( "{call insert_Cinfo(?,?)} ");
st.setString(1, "104 ");
st.setString(2, "newin ");
st.executeUpdate();
st.close();
conn.close();
}
//利用rs读取每一条记录
public boolean next() throws Exception
{
boolean nextrow=rs.next();
if(nextrow)
{
id=rs.getString( "id ");
name=rs.getString( "name ");
return true;
}
else
{
rs.close();
st.close();
conn.close();
return false;
}
}
}
------解决方案--------------------