Total members 11890 |It is currently Sat Apr 20, 2024 7:01 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Code:
import javax.servlet.ServletException;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.SQLException;

import java.util.HashMap;
//import com.lara.rms.db.ConnectionPool;
import java.util.Map;

public class AddConstructionServlet extends HttpServlet
{
   public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
   {
      
      System.out.println("*************************");
      System.out.println(" BUSINESS LOGIC ");
      System.out.println("*************************");
      PrintWriter out = response.getWriter();
      Connection con=null;
       try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
       con = DriverManager.getConnection("jdbc:odbc:dberp","system","tiger");
       }
       catch(Exception e)
       {
          e.printStackTrace();
       }
      /* String UserName = null;
         String Name = null;
         String Email = null;
         String Address = null;
         String City= null;
         String State = null;
         String Pincode = null;*/
         Map allParams = request.getParameterMap();
         //RequestDispatcher dispatcher = null;
         String UserName[] = (String[])allParams.get("UserName");
         String Name[] = (String[])allParams.get("Name");
         String Email[] = (String[])allParams.get("Email");
         String Address[] = (String[])allParams.get("Address");
         String City []= (String[])allParams.get("City");
      String State[] = (String[])allParams.get("State");
         String Pincode[] = (String[])allParams.get("Pincode");
         Statement stmt=null;
      
         String sql = "insert into Supplier(UserName, Name, Email, Address, City, State, Pincode)" +
         " values('" + UserName + "','" + Name + "','" + Email + "'," + Address + ",'" + City + "'," + State + ",'" + Pincode +  "')";
         System.out.println("sql:"+sql);                                 
         out.println("insertation complete");   
         try
         {
            stmt = con.createStatement();
            stmt.executeUpdate(sql);
         }
         catch(SQLException ex)
         {
            ex.printStackTrace();
         }
         finally
         {
            try
            {
               if(stmt != null)
            {
                  stmt.close();
               stmt= null;
            }
            }
         catch(SQLException e)
         {
         e.printStackTrace();
         }
         try
         {
            if(con != null)
               {
               con.close();
                  con= null;
            }
         }
      catch(SQLException e)
      {
            e.printStackTrace();
         }
      }
      }
   }


Plz help me !!!
Actually I'm getting problem that this code is not fetching data from my html form but rather sending null value in database in place of entered value.




Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Servlet Help for my project!!
 how to run servlet and rmi     -  
 jsp and servlet     -  
 JSP and Servlet     -  
 Servlet & JSP     -  
 servlet coding     -  
 SERVLET/JSP DOUBT     -  
 Java Servlet and JSP     -  
 servlet connectivity with ms access     -  
 How can i redirect to a one servlet from a two jsp page?     -  
 Best Books for Servlet and JDBC     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com