Results 1 to 2 of 2
  1. #1
    niksipandit is offline Member
    Join Date
    Sep 2011
    Posts
    9
    Rep Power
    0

    Default error occured:-java.lang.NullPointerException

    Here is my code:-

    <%@ page import="java.sql.*" %>
    <%
    String payer = request.getParameter("payer");
    String payment = request.getParameter("payment");
    String date = request.getParameter("date");
    String details = request.getParameter("details");
    String[] vals = request.getParameterValues("all");

    try{
    Class.forName("oracle.jdbc.OracleDriver");
    Connection conn = DriverManager.getConnection(
    "jdbc:oracle:thin:@172.16.2.48:1521:DIANAPRD", "difbank", "difbank");
    PreparedStatement ps=conn.prepareStatement("INSERT INTO p_city VALUES (?,?,?,?,?)");
    ps.setString(1,payer );
    ps.setString(2,payment );
    ps.setString(3,date );

    for (String val : vals)
    { ps.setString(4, val);
    }
    ps.setString(5,details);
    ps.execute();
    ps.close(); %>
    <html>
    <center>
    <body>
    <b>Successfully inserted expenditure.You want to insert another expenditure pls click</b>
    <a href = "C:\workspace\HouseManagement\WebContent\ExpendInf o.jsp"><b>INFORMATION FILL</b></a>
    </body>
    </center>
    </html>
    <%}
    catch(Exception e)
    {
    out.println("error occured:-"+e);
    } %>



    please tell me where I hv mistaken.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: error occured:-java.lang.NullPointerException

    Your mistake is putting Java code into a JSP.
    That code should be in a servlet or, since it's all to do with DB access, in a data layer that the servlet calls.
    The JSP should simply be for displaying the result forwarded on by that servlet.

Similar Threads

  1. java.lang.NullPointerException Error
    By Manfizy in forum NetBeans
    Replies: 3
    Last Post: 02-24-2011, 07:27 AM
  2. Please solve my error occured java.lang.NullPointerException
    By Viruthagiri in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-24-2010, 01:08 PM
  3. Please solve my java.lang.NullPointerException error.?
    By Viruthagiri in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-23-2010, 10:30 PM
  4. Replies: 1
    Last Post: 12-05-2009, 08:28 AM
  5. Replies: 2
    Last Post: 07-02-2007, 03:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •