java数据库删除 *** 作

java数据库删除 *** 作,第1张

简单实现代码如下:

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


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/6772807.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-28
下一篇 2023-03-28

发表评论

登录后才能评论

评论列表(0条)

保存