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

📄 notedaoimpl.java.bak

📁 这是一个简单的用B/S写的留言板小程序,用jsp和javaBean实现的
💻 BAK
字号:
 package note1;
  
 import note1.*;
 import note1.note;
 import login1.dbcon;
 import java.sql.*;
 import java.io.*;
 import java.util.*;
 public class noteDAOimpl implements noteDAO
 {
 	  public void insert(note note)throws Exception
 	  {
 	  	String sql="insert into note2(title,author,content) values(?,?,?)";
 	  	PreparedStatement pstmt=null;
 	  	dbcon dbcon=null;
 	  	dbcon=new dbcon();
 	  	try
 	  	{
 	  		pstmt=dbcon.getcon().prepareStatement(sql);
 	  		pstmt.setString(1,note.gettitle());
 	  		pstmt.setString(2,note.getauthor());
 	  		pstmt.setString(3,note.getcontent());
 	  		pstmt.executeUpdate();
 	  		pstmt.close();
 	  	}
 	  	catch(Exception e)
 	  	{
 	  		throw new Exception("操作出现错误!!!!");
 	  	}
 	  	finally
 	  	{
 	  		dbcon.close();
 	  	}
 	  }
	public void update(note note)throws Exception
	{
		String sql="update note2 set title=?,author=?,content=? where id=?";
		PreparedStatement pstmt=null;
		dbcon dbcon=null;
		dbcon=new dbcon();
		try
		{
			pstmt=dbcon.getcon().prepareStatement(sql);
			pstmt.setString(1,note.gettitle());
			pstmt.setString(2,note.getauthor());
			pstmt.setString(3,note.getcontent());
			pstmt.setInt(4,note.getid());
			pstmt.executeUpdate();
			pstmt.close();
		}
		catch(Exception e)
		{
			throw new Exception("操作出现错误!!!");
		}
		finally
		{
			dbcon.close();
		}
	}
	public void delete(int id)throws Exception
  {
  	String sql="delete from note2 where id=?";
		PreparedStatement pstmt=null;
		dbcon dbcon=null;
		dbcon=new dbcon();
		try
		{
			pstmt=dbcon.getcon().prepareStatement(sql);
			pstmt.setInt(1,id);			
			pstmt.executeUpdate();
			pstmt.close();
		}
		catch(Exception e)
		{
			throw new Exception("操作出现错误!!!");
		}
		finally
		{
			dbcon.close();
		}
  }
	public note findbyname(int id)throws Exception
	{
		note note=null;
		String sql="select * from note2 where id=?";
		PreparedStatement pstmt=null;
		dbcon dbcon=null;
		dbcon=new dbcon();
		try
		{
			pstmt=dbcon.getcon().prepareStatement(sql);
			pstmt.setInt(1,id);			
			ResultSet rst=pstmt.executeQuery();
			while(rst.next())
			{
				note=new note();
				note.setid(rst.getInt(1));
				note.settitle(rst.getString(2));
				note.setauthor(rst.getString(3));
				note.setcontent(rst.getString(4));
		}
			pstmt.close();
			rst.close();
		}
		catch(Exception e)
		{
			throw new Exception("操作出现错误!!!");
		}
		finally
		{
			dbcon.close();
		}
		return note;
	}
	
	public List findall()throws Exception
	{
		List all=new ArrayList();
		String sql="select * from note2";
		PreparedStatement pstmt=null;
		dbcon dbcon=null;
		dbcon=new dbcon();
		try
		{
			pstmt=dbcon.getcon().prepareStatement(sql);
						
			ResultSet rst=pstmt.executeQuery();
			while(rst.next())
			{
				note note=new note();
				note.setid(rst.getInt(1));
				note.settitle(rst.getString(2));
				note.setauthor(rst.getString(3));
				note.setcontent(rst.getString(4));
				all.add(note);
		}
			pstmt.close();
			rst.close();
		}
		catch(Exception e)
		{
			throw new Exception("操作出现错误!!!");
		}
		finally
		{
			dbcon.close();
		}
		return all;
	}
	public List findbylike(String str)throws Exception
	{
		List all=new ArrayList();
		String sql="select * from note2 where title like ? or author like ? or content like ?";
		PreparedStatement pstmt=null;
		dbcon dbcon=null;
		dbcon=new dbcon();
		try
		{
			pstmt=dbcon.getcon().prepareStatement(sql);
			pstmt.setString(1,"%"+str+"%");
			pstmt.setString(2,"%"+str+"%");
			pstmt.setString(3,"%"+str+"%");
			ResultSet rst=pstmt.executeQuery();
			while(rst.next())
			{
				note note=new note();
				note.setid(rst.getInt(1));
				note.settitle(rst.getString(2));
				note.setauthor(rst.getString(3));
				note.setcontent(rst.getString(4));
		}
			pstmt.close();
			rst.close();
		}
		catch(Exception e)
		{
			throw new Exception("操作出现错误!!!");
		}
		finally
		{
			dbcon.close();
		}
		return all;
	}
 }

⌨️ 快捷键说明

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