EmployeeDao.java
//删除数据
public boolean deleteEmployeeById(int id){
boolean result = false
try{
con = DBCon.getConn()
String sql = "delete from tb_employee where id=?"
pstmt = (PreparedStatement) con.prepareStatement(sql)
pstmt.setInt(1, id)
int i = pstmt.executeUpdate()
if(i == 1)
result = true
}catch(Exception e){
e.printStackTrace()
}finally{
try{
if(pstmt != null){
pstmt.close()
}
}catch(Exception e){
e.printStackTrace()
}
try{
if(con != null){
con.close()
}
}catch(Exception e){
e.printStackTrace()
}
}
return result
}
TestSql2.java
package com.sql.test
import com.sql.dao.EmployeeDao
public class TestSql02 {
public static void main(String[] args){
boolean result = EmployeeDao.getInstance().deleteEmployeeById(1)
if(result == true){
System.out.println("删除成功!")
}else{
System.out.println("删除失败!")
}
}
}
直接用jdbc执行sql语句块declare @procName varchar(500) declare cur cursor -- 定义个游标for select [name] from sysobjects where type = 'p'open cur -- 打开游标 fetch next from cur into @procName --迭代游标并给@procName赋值 while @@fetch_status = 0 --判断迭代状态 begin if @procName <>'DeleteAllProcedures' exec('drop procedure ' + @procName) -- 动态执行sql语句 fetch next from cur into @procName end close cur deallocate cur欢迎分享,转载请注明来源:内存溢出
评论列表(0条)