用J2EE开发的网站,可以应用到图书馆,图书超市

源代码在线查看: bg_message.java

软件大小: 3721 K
上传用户: zhuying0000
关键词: J2EE 网站 图书馆 图书
下载地址: 免注册下载 普通下载 VIP

相关代码

				package ksnb;
				import java.sql.*;
				import java.util.*;
				import javax.servlet.http.*;
				import java.text.*;
				public class BG_Message {
				
				    private conn c = null;
				    private Connection con = null;
				    private Statement stm = null;
				    private ResultSet rs = null;
				    private Collection ret = null;
				    private String strSql=null;
				    private int id=0 ;
				
				    public BG_Message() {
				        try {
				            c = new conn();
				            con = c.getConncetion();
				
				        } catch (Exception e) {
				            System.out.println(e.toString());
				        }
				        ret=new ArrayList();
				
				    }
				    private static String convert( String str )
				   {
				       try
				       {
				           byte[] bytesStr=str.getBytes( "ISO-8859-1" ) ;
				           return new String( bytesStr, "gb2312" ) ;
				       }
				       catch( Exception ex)
				       {
				           return str ;
				       }
				   }
				
				   public void Query(HttpServletRequest request)
				   {
				       id=Integer.parseInt((String)request.getParameter("Id"));
				       System.out.println(id);
				       strSql = "select * from Shop_Gbook_info where Product_id= '" + id +
				                     "' order by Date_time desc";
				            System.out.println(strSql);
				       try {
				            stm = con.createStatement();
				            rs = stm.executeQuery(strSql);
				            String Content = null;
				            String Author = null;
				            java.sql.Date date = null;
				            int Book=0;
				            int Id=0;
				
				
				             while(rs.next())
				               {
				                   Id=rs.getInt("Id");
				                   Book=rs.getInt("Product_id");
				                   Content=rs.getString("Content");
				                   Author=rs.getString("Author");
				                   date=rs.getDate("Date_time");
				
				                   MessageBean message=new MessageBean();
				                   message.setId(Id);
				                   message.setBook(Book);
				                   message.setContent(Content);
				                   message.setAuthor(Author);
				                   message.setDatetime(date);
				
				                   ret.add(message);
				
				              }
				              request.setAttribute("ret",ret);
				              rs.close();
				              stm.close();
				
				        } catch(Exception e){System.out.println(e);}
				
				   }
				   public void Delete(HttpServletRequest request)
				   {
				       int Id=Integer.parseInt((String)request.getParameter("cmd1"));
				       strSql="delete from Shop_Gbook_info where Id="+Id;
				       System.out.println(strSql);
				       try {
				           stm = con.createStatement();
				           stm.executeUpdate(strSql);
				           stm.close();
				       }
				       catch(Exception e)
				       {
				           System.out.println(e.toString());
				       }
				
				   }
				
				
				
				
				}
							

相关资源