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

📄 trans_log2.java

📁 以Servlet以及JDBC实现的网站实例
💻 JAVA
字号:

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;



public class trans_log extends HttpServlet {
    
    
    ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
    
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException  
    {
        response.setContentType("text/html");
	
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<body background=\"file:/home/xu/servlet/jsdk2.1/examples/images/bg3.gif\">");
        out.println("<head>");
        out.println("</head>");
        out.println("<body bgcolor=\"white\">");
	
        String title = rb.getString("requestparams.title");
        
        String num = request.getParameter("num");
      	
        String depart = request.getParameter("depart");
	
		String dest  = request.getParameter("dest");
	
		String jour  = request.getParameter("jour");
		String mois = request.getParameter("mois");
		String annee = request.getParameter("annee");
	
		String type = request.getParameter("type_trans");
		String duree = request.getParameter("duree");
		
		String description= request.getParameter("descri");	
	
		String I_V = request.getParameter("I_V");
	
		String num_aff,depart_aff,dest_aff,jour_aff,mois_aff,annee_aff,type_aff,duree_aff,description_aff;		
	
		String sqlString_aff = "select * from trans_log";
	
		Statement smtp=null;
	
		Connection con=null ;
		try{
	    		Class.forName("oracle.jdbc.driver.OracleDriver");
	    		con=DriverManager.getConnection("jdbc:oracle:thin:@capucine:1521:ens","lic329","oracle");
	       }
		catch(Exception e)
	    {
			System.err.println(e);
	    }
	     

       if(I_V.equals("Inserer")) 
		{
			String sqlString_Ins = "insert into trans_log values("+"'"+num+"','"+depart+"','"+dest+"','"+jour+
			               "','"+mois+"','"+annee+"','"+type+"','"+duree+"','"+description+"')";	
					       				
		
		try
		{		
			smtp=con.createStatement();  								       
			smtp.executeUpdate(sqlString_Ins);			 		      		
		}
		catch(SQLException e)
		{      
			System.err.println(e);
		}
	

        	out.println("<p><h1>L'insertion est fait</h1></p><br><br><br>");
			    
    
		
		try
		{      			
			ResultSet rs = smtp.executeQuery(sqlString_aff);
				
			while (rs.next())
			{
				num_aff = rs.getString(1);
				depart_aff = rs.getString(2);
				dest_aff = rs.getString(3);
				jour_aff = rs.getString(4);
				mois_aff = rs.getString(5);
				annee_aff = rs.getString(6);
				type_aff = rs.getString(7);
				duree_aff = rs.getString(8);
				description_aff = rs.getString(9);
			
				
				out.println("Numero de moyen        : " +num_aff+"<br>");
				out.println("Au Départ de      	: " +depart_aff+"<br>");
				out.println("A Destination de  		: "+dest_aff+"<br>");
			  	out.println("Date              		: "+jour_aff+"/"+mois_aff+"/"+annee_aff+"<br>");
				out.println("Type de transport 		: "+type_aff+"<br>");
				out.println("Durée             	: " +duree+" heures<br>");
			 	out.println("Descrption de Logement : <br>");
				out.println(description_aff+"<br><br>");
			}
		}
		catch(SQLException e)
		{      
			System.err.println(e);
		}
		
		out.println("<p><h2>Vous voulez <a href=\"http://localhost:8080/examples/servlets/trans_log_root.html\">"+
		            "continuer</a>  ou <a href=\"http://localhost:8080/examples/servlets/trans_log.html\">"+
			    	"s'arrêter</a> ?");
			
	}
	else
	{	
		if (I_V.equals("Suppression")) 	
		{	
		
			String sqlString_Sup = "delete from trans_log where depart = '"+depart+"' ";	
			
			try
		    	{	 
			  	smtp=con.createStatement();								
			     	smtp.executeUpdate(sqlString_Sup);						
		   	}
			catch(SQLException e)
		    	{      
				System.err.println(e);
		    	}
			
			out.println("<p><h1>La Suppression est fait</h1></p><br><br><br>");
			
			try
		  	{    			
				ResultSet rs = smtp.executeQuery(sqlString_aff);
				
				while (rs.next())
				{
					num_aff = rs.getString(1);
					depart_aff = rs.getString(1);
					dest_aff = rs.getString(2);
					jour_aff = rs.getString(3);
					mois_aff = rs.getString(4);
					annee_aff = rs.getString(5);
					type_aff = rs.getString(6);
					duree_aff = rs.getString(7);
					description_aff = rs.getString(8);
			
					
					out.println("Numero de moyen        : " +num_aff+"<br>");
					out.println("Au Départ de      	: "+depart_aff+"<br>");
					out.println("A Destination de  		: "+dest_aff+"<br>");
			  		out.println("Date              		: "+jour_aff+"/"+mois_aff+"/"+annee_aff+"<br>");
					out.println("Type de transport 		: "+type_aff+"<br>");
					out.println("Durée             	: "+duree+" heures<br>");
			 		out.println("Descrption de Logement : <br>");
					out.println(description_aff+"<br><br>");
				}
			}
			catch(SQLException e)
			{      
				System.err.println(e);
			}
		
			out.println("<p><h2>Vous voulez <a href=\"http://localhost:8080/examples/"+
			            "servlets/trans_log_root.html\">continuer</a>  ou <a href=\"http:"+
				    "//localhost:8080/examples/servlets/trans_log.html\">"+
			            "s'arrêter</a> ?");
			
		}	
		else
		{	
			if(I_V.equals("Vider")) 	
			{
				try
		    	 	{	
					String sqlString_Vide = null;
			  		smtp=con.createStatement();  				
					sqlString_Vide = "delete from trans_log";						     
				 	smtp.executeUpdate(sqlString_Vide);
			 		 

		   		}
				
				catch(SQLException e)
		    		{      
					System.err.println(e);
		    		}
				
				out.println("<p><h2>La table de MOYEN DE TRANSPORT ET DE LOGEMENT est maintenant"+
				            " vidé.</h2></p>");
				out.println("<p><h2>Vous voulez <a href=\"http://localhost:8080/examples/servlets/"+
				            "trans_log_root.html\">continuer</a>  ou <a href=\"http://localhost:8080"+
					    "/examples/servlets/trans_log.html\">s'arrêter</a> ?");
			}					
		}
				
	}	
	
	out.println("</body>");
	out.println("</html>");				
		
    }
    
 


        
    public void doPost(HttpServletRequest request,
		       HttpServletResponse response)
	throws IOException, ServletException
    {
	doGet(request, response);	
    }
}

 

⌨️ 快捷键说明

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