Total members 10262 | Gratitudes |It is currently Thu May 24, 2012 10:25 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Question
 Question subject: Servlet Help for my project!!
PostPosted: Tue Apr 21, 2009 6:49 am 
Offline
Newbie
User avatar

Joined: Tue Apr 21, 2009 6:34 am
Posts: 1
Has thanked: 0 time
Have thanks: 0 time

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.


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 mini project
 Connect to database Microsoft access within jsp servlet
 need mini chat voice project.
 online shopping project
 How can i redirect to a one servlet from a two jsp page?
 project source code in java
 project topic in java
 Servlet & JSP
 I am doing my BCA final year. Looking out for a mini project
 need of java code for doing project

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team