type="text"
class="inputgri"
name="username"
valve
=
<%=
request.getAttribute("computers")>/>直接写在JSP页面中其他还有很多方法.不过在这之前你需要将值放进request中.
简单实现代码如下: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("删除失败!")
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)