Hi All,
I was trying to execute a servlet which goes and insert into database ,
I am using MS ACCESS as a database.

My Servler code is:

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

public class regn extends HttpServlet
         {
                Connection con      = null;

                public void init(ServletConfig config) throws ServletException
                {
                        super.init(config);
                        establishConnection();
                }


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

                public void destroy()
                {
                        if (con != null)
                        {
                        try
                                {
                                        con.close();
                                }       catch (SQLException ex) {}
                        }
                }

            private void establishConnection()
            {
                try
                   {
                        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  //loads the 
driver
                  this.con =
DriverManager.getConnection("jdbc:odbc:subha","subha","subha");
                   } catch (ClassNotFoundException ex) {} catch (SQLException ex) {}

         }

          public void doGet(HttpServletRequest request, HttpServletResponse
response) throws IOException, ServletException
          {
                response.setContentType("text/html");
                PrintWriter out = response.getWriter();
                String loginid = request.getParameter("loginid");
                System.out.println("query");
                try {
                        Statement stmt = con.createStatement();
                        String SQLStr = new String();
                        SQLStr = "INSERT INTO user(LoginId,Name,Address) VALUES((\"" +
request.getParameter("loginid") + "\",\"" + request.getParameter("name") +
"\",\"" + request.getParameter("address") + "\")";
                        int rows = stmt.executeUpdate(SQLStr);
                        stmt.close();
                        con.close();
                   } catch (SQLException e) {}

                        out.println("<html>");
                        out.println("<head>");
                        out.println("<title>Sorry!!!</title>");
                        out.println("</head>");
                        out.println("<body>");
                        out.println("<p><big><big>Sorry!!! There are some problems");
                        out.println("<p>&nbsp;");
                        out.println("</body></html>");

                }
        }


THE ERROR IS
Error: 500
Location: /examples/servlet/regn
Internal Servlet Error:

java.lang.NullPointerException:
        at regn.doGet(regn.java:52)
        at regn.doPost(regn.java:21)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
        at org.apache.tomcat.core.Handler.service(Compiled Code)
        at org.apache.tomcat.core.ServletWrapper.service(Compiled Code)
        at org.apache.tomcat.core.ContextManager.internalService(Compiled Code)
        at org.apache.tomcat.core.ContextManager.service(Compiled Code)
        at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(Compiled
Code)
        at org.apache.tomcat.service.TcpWorkerThread.runIt(Compiled Code)
        at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(Compiled Code)
        at java.lang.Thread.run(Compiled Code)



Please tell me the reason for this , and how could i solve it..


Regards
subha


_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to