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

📄 ecminfdel.java

📁 IBM AGLET及JAVA实现的电子商务系统源码
💻 JAVA
字号:
import java.io.*;
import java.net.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;


public class ecmInfDel extends HttpServlet{		
	int DelCount=0;
	String ObjType,OpType;
	String isSelect,delCon,dbName,tableName;
	ResultSet rs;
	tableSql t;		
        String temp,insert0,delete0,cancel0,update0;  
	
	public void init(ServletConfig conf) throws ServletException {
		super.init(conf);
	}
	
	public void service(HttpServletRequest req,HttpServletResponse resp)
				throws ServletException,IOException{	
		ServletOutputStream out=resp.getOutputStream();
        temp="插入";
        insert0=new String(temp.getBytes("GBK"),"ISO8859_1");
        temp="删除";	
        delete0=new String(temp.getBytes("GBK"),"ISO8859_1");
        temp="取消";
        cancel0=new String(temp.getBytes("GBK"),"ISO8859_1");
        temp="更改";
        update0=new String(temp.getBytes("GBK"),"ISO8859_1");
		
		dbName=req.getParameter("DbName");
		tableName=req.getParameter("TableName");
		delCon=req.getParameter("Conditions");
		if (req.getParameter("DbName").equals("Ecmdb")){;
			t = new tableSql("Ecmdb");
		}	  
		//WatchParameters(req,out);
		//删除所选择记录
		if (req.getParameter("IsSelect").equals("select")) {
			System.out.println("it will delete selected records");
			int i=1;
			Enumeration keys;	
			String kkey,values;
			keys=req.getParameterNames();
			while (keys.hasMoreElements()) {
				kkey=(String)keys.nextElement();
				values=req.getParameter(kkey);
				if (kkey.startsWith("record")){
					DelCount=DelCount+t.recordDelete("delete from "+tableName+" where "+tableName+".num="+values);
					System.out.println("delete from "+tableName+" where "+tableName+".num="+values);		
				}			
			}
		}
		//根据输入条件删除记录
		if (req.getParameter("IsSelect").equals("noselect")) {
			System.out.println("this delete condition is:"+delCon);	
			DelCount=t.recordDelete("delete from "+tableName+" where "+tableName+"."+delCon);	
			//System.out.println("delete from ment where comment."+delCon);
		}
		

		System.out.println("i go delete table");		
		resp.setContentType("text/html");
		out.println("<HTML>");
		out.println("<HEAD><TITLE>Delete Goods</TITLE></HEAD>");
		out.println("<BODY bgcolor=\"#f5f5f5\">");
                String temp000,temp001;
                temp000="请选择你要删除的记录";
                temp001=new String(temp000.getBytes("GBK"),"ISO8859_1");
		out.println("<hr><B>"+temp001+"</B><BR>");
//		out.println("<HR><B>It will delete your select records!</B><BR>");
		out.println("<FORM METHOD=POST ACTION=\"/servlet/ecmInfDel\">");
		//if (dbName.equals("Sysdb"))
		//	DispTable("select * from  "+tableName,out);
		//else 
			DispTable("select * from  "+tableName,out);
		out.println("<HR>");
		out.println("<INPUT TYPE=\"hidden\" name=\"DbName\" value=\""+dbName+"\">");
		out.println("<INPUT TYPE=\"hidden\" name=\"TableName\" value=\""+tableName+"\">");
                System.out.println(temp000);
		temp000="按所选择的记录删除";
                System.out.println(temp000);
		temp001=new String(temp000.getBytes("GBK"),"ISO8859_1");
		out.println("<INPUT TYPE=\"radio\" NAME=\"IsSelect\" VALUE=\"select\" CHECKED>"+temp001+"<BR>");		
		temp000="按输入条件删除";
		temp001=new String(temp000.getBytes("GBK"),"ISO8859_1");
		out.println("<INPUT TYPE=\"radio\" NAME=\"IsSelect\" VALUE=\"noselect\">"+temp001+"<BR>");		
		//out.println("<INPUT TYPE=\"radio\" NAME=\"IsSelect\" VALUE=\"select\" CHECKED>"+te<BR>");		
		//out.println("<INPUT TYPE=\"radio\" NAME=\"IsSelect\" VALUE=\"noselect\" >Delete according to  input conditions<BR> ");		
                
                temp000="请输入你的删除条件";
                temp001=new String(temp000.getBytes("GBK"),"ISO8859_1");
//		out.println("<hr><b>"+temp001+"</b><br>");
		out.println(temp001+" :<INPUT TYPE=TEXT SIZE=20 NAME=\"Conditions\"><BR>");
		out.println("<INPUT TYPE=SUBMIT VALUE="+delete0+">");		
		out.println("<INPUT TYPE=RESET VALUE="+cancel0+">");		
		out.println("</FORM>");				
		out.println("<BR><HR>");
		if (DelCount>0)
			out.println("You have succeed to delete "+DelCount+" records!");
		else out.println("You have fail to delete!");
		out.println("</BODY></HTML>");
	}
	
	public void Destroy(){
		t.closeConnect();
	}
	////display the Parameter and values
	public void WatchParameters(HttpServletRequest req,ServletOutputStream out)
			throws ServletException,IOException{
		int i=1;
		Enumeration keys;	
		String kkey,values;
		keys=req.getParameterNames();
		while (keys.hasMoreElements()) {
			kkey=(String)keys.nextElement();
			values=req.getParameter(kkey);
			out.println("<P>"+"key: "+kkey+" equals value:"+values);
		}
	}	
	
public void DispTable(String query,ServletOutputStream out) throws ServletException,IOException{
		//out.println("<H1>TABLE RESULTS:</H1>");
		out.println("<TABLE BORDER=\"1\" ALIGN=\"CENTER\">");
		try{
			synchronized(this) {				
				int i=0,j=0;				
   			String tmpstr,checkbo;
   			rs=t.recordSql(query);					
   			ResultSetMetaData rsmd=rs.getMetaData();
   			int numCols=rsmd.getColumnCount();  				
   		   //display each column title
   			out.print("<TD>column name");
   			for(i=1;i<=numCols;i++){
   				//out.println(new String(name.getBytes("GBK"),"ISO8859_1") );
   				out.print("<TD>"+new String(rsmd.getColumnLabel(i).getBytes("GBK"),"ISO8859_1") );
   			   System.out.println("display the title");
   			   System.out.println(new String(rsmd.getColumnLabel(i).getBytes("GBK"),"ISO8859_1") );
   			}
   			out.println("<TR>"); 
   			System.out.println("enter display the table records");  		
   		   //display each column data
   			while (rs.next()){		
   				//tmpstr=rs.getString(2);
   				//out.print("<TD><INPUT TYPE=checkbox NAME=\"record"+i+"\">");		  				
					j++;	
   				checkbo=rs.getString(1);
   				out.print("<TD><INPUT TYPE=\"checkbox\" NAME=\"record"+j+"\""+" value=\""+checkbo+"\">");		   	
					out.print("<TD>"+checkbo);
					
					for(i=2;i<=numCols;i++){
						tmpstr=rs.getString(i);	
						if(rs.wasNull())
							out.print("<TD>NULL");
						else 
							out.print("<TD>"+new String(tmpstr.getBytes("GBK"),"ISO8859_1") );
					}
					out.println("<TR>");
				}
			}
			out.println("</TABLE>");
		}
		catch(SQLException ex){
			System.out.println("\n***SQLException caught ***\n");
			while (ex != null){
				System.out.println("SQLState:"+ex.getSQLState());
				System.out.println("Message:"+ex.getMessage());	
				System.out.println("Vendor:"+ex.getErrorCode());
				ex=ex.getNextException();
				System.out.println("");
			}
			out.println("</TABLE>");
		}						   	
	}
	
}

⌨️ 快捷键说明

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