⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 itemdao.java

📁 实现办公自动化系统
💻 JAVA
字号:
package com.oa.struts.perOffice.modle;
import java.sql.*;

import com.oa.util.DBConn;

public class ItemDAO {
	Connection con=null;
	PreparedStatement pstmt=null;
	ResultSet rs=null;
	DBConn db=null;
	
	public ItemDAO() {
		super();
		// TODO Auto-generated constructor stub
	}
	
	//注册查询用户信息
	
	
	

	public boolean insertItem(Tdothing td)
	{
		boolean result=false;
		try
		{
			String sql="insert into tb_todo values(TODO_SEQ.nextval,?,?,?,?)";
			db=new DBConn();
			con=db.getConnection();
			pstmt=con.prepareStatement(sql);
			pstmt.setInt(1, 102);
			pstmt.setString(2,td.getTopic());
			pstmt.setString(3,td.getContent());
			pstmt.setInt(4,0);	
       
			int i=pstmt.executeUpdate();
			if(i>0)
			{
				result=true;
			}
				
			if(pstmt!=null) pstmt.close();
			if(con!=null) con.close();		
			
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		
		return result;
	}
	

	//显示所有分类信息
	public String  displayAllItem()
	{
		StringBuffer stf=new StringBuffer();
		try
		{
			String sql="select * from tb_todo  where userid=102";
			db=new DBConn();
			con=db.getConnection();
			pstmt=con.prepareStatement(sql);	
			rs=pstmt.executeQuery();
			
		    stf.append("<link  rel='stylesheet' href='../css/main_bottom.css' type='text/css'>");
			stf.append("<style type='text/css'>");
			stf.append("<!--");
			stf.append("a:link{");
			stf.append("text-decoration: none");
			stf.append("}");
			stf.append("a:visited {");
			stf.append("text-decoration: none");
			stf.append("}");
			stf.append("a:hover {");
			stf.append("text-decoration: none");
			stf.append("}");
			stf.append("a:active {");
			stf.append("text-decoration: none");
			stf.append( "}");
			stf.append("-->");
			stf.append("</style>");
			stf.append("<table width='90%' border='1'align='center' class='t1'>");
			stf.append("<tr>");
			stf.append("<td colspan='5'>&nbsp; 待办工作清单|<a href='/F-YOA/personalOffice/addItem.jsp'>记录待办事项</a></td>");
			stf.append("</tr>");
			stf.append("<tr>");
			stf.append("<td>编号</td>");
			stf.append("<td>标题</td>");
			stf.append("<td>代办内容</td>");
			stf.append("<td>完成与否</td>");
			stf.append("<td>是否删除</td>");
			stf.append("</tr>");
			while(rs.next())
			{
				int id=rs.getInt("id");
				String topic=rs.getString("topic");
				String content=rs.getString("content");
				int iscomplete=rs.getInt("iscomplete");
				

			
				
				stf.append("<tr>");
				stf.append("<td>"+id+"</td>");
				stf.append("<td>"+topic+"</td>");
				stf.append("<td>"+content+"</td>");
				stf.append("<td>"+iscomplete+"</td>");	
				stf.append("<td><a href=/F-YOA/itemControl.do?action=del&id="+id+">删除</a></td>");
				stf.append("</tr>");			
				
			}
			stf.append("</table>");
			
			
			//System.out.println("stf="+stf);
			
			if(rs!=null) rs.close();
			if(pstmt!=null) pstmt.close();
			if(con!=null) con.close();		
			
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return stf.toString();	
		
	}
	
	public boolean deleteItem(int id)
	{
		boolean result=false;
		try
		{
			String sql="delete from tb_todo where id=?";
			db=new DBConn();
			con=db.getConnection();
			pstmt=con.prepareStatement(sql);
			pstmt.setInt(1,id);
			int i=pstmt.executeUpdate();
			if(i>0)
			{
				result=true;
			}
				
			if(pstmt!=null) pstmt.close();
			if(con!=null) con.close();		
			
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		
		return result;
	
	}
	
	
	//根据id查询Item
	public Tdothing searchItem(int id)
	{
		Tdothing td=new Tdothing();
		try
		{
			String sql="select * from tb_todo where id=?";
			db=new DBConn();
			con=db.getConnection();
			pstmt=con.prepareStatement(sql);
			pstmt.setInt(1,id);		
			rs=pstmt.executeQuery();
			
			String topic="";
			String content="";
			int  iscomplete=0;
			
	
			while(rs.next())
			{
				topic=rs.getString("topic");
				content=rs.getString("content");
				iscomplete=rs.getInt("complete");
				
			}
			td.setID(id);
			td.setTopic(topic);
			td.setContent(content);
			
			if(rs!=null) rs.close();
			if(pstmt!=null) pstmt.close();
			if(con!=null) con.close();		
			
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}	
		return td;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -