📄 perofficedao.java
字号:
package com.oa.struts.perOffice.modle;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import com.oa.util.DBConn;
import com.oa.struts.vo.*;
public class PerOfficeDAO
{
Connection con=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
DBConn db=null;
public PerOfficeDAO() {
super();
// TODO Auto-generated constructor stub
}
//插入待办事项
public boolean insertItem(Tdothing thing)
{
boolean result=false;
try
{
String sql="insert into tb_toDo values(?,?)";
db=new DBConn();
con=db.getConnection();
pstmt=con.prepareStatement(sql);
pstmt.setString(1,thing.getTopic());
pstmt.setString(2,thing.getContent());
int i=pstmt.executeUpdate();
System.out.println("i="+i);
if(i>0)
{
result=true;
}
if(pstmt!=null) pstmt.close();
if(con!=null) con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return result;
}
//修改待办事项
public int updateItem(String topic,String content,int id)
{
int i=0;
try
{
String sql="update tb_toDo set topic=?,content=? where id=?";
db=new DBConn();
con=db.getConnection();
pstmt=con.prepareStatement(sql);
pstmt.setString(1,topic);
pstmt.setString(2,content);
pstmt.setInt(3,id);
i=pstmt.executeUpdate();
if(i>0)
{
i=1;
}
if(pstmt!=null) pstmt.close();
if(con!=null) con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return i;
}
//删除待办事项
public int deleteItem(int id)
{
int i=0;
try
{
String sql="delete from tb_toDo where id=?";
db=new DBConn();
con=db.getConnection();
pstmt=con.prepareStatement(sql);
pstmt.setInt(1,id);
i=pstmt.executeUpdate();
if(i>0)
{
i=1;
}
if(pstmt!=null) pstmt.close();
if(con!=null) con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return i;
}
//显示所有的待办事项
public List allItem(int founder)
{
Tdothing thing=new Tdothing();
List list=new ArrayList();
try
{
String sql="select * from tb_toDo";
db=new DBConn();
con=db.getConnection();
pstmt=con.prepareStatement(sql);
rs=pstmt.executeQuery();
String topic="";
String content="";
int id;
int complete;
while(rs.next())
{
id=rs.getInt(1);
topic=rs.getString(2);
content=rs.getString(3);
thing.setID(id);
thing.setTopic(topic);
thing.setContent(content);
list.add(thing);
}
if(rs!=null) rs.close();
if(pstmt!=null) pstmt.close();
if(con!=null) con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return list;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -