Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please solve my java.lang.NullPointerException error.?

 
Viruthagiri Thirumalvalavan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys i got file enroll.jsp while executing that i got java.lang.NullPointerException. So please solve this,

my code as follows

Code:
//enroll.jsp//
<%@ page import="INCLUDES.DBConnection"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<jsp:useBean id="DB" scope="page" class="INCLUDES.DBConnection"/>
<jsp:setProperty name="DB" property="*"/>
<jsp:useBean id="DB1" scope="page" class="INCLUDES.DBConnection"/>
<jsp:setProperty name="DB1" property="*"/>
<%
int course_id=Integer.parseInt(request.getParameter("course_id"));
int no_of_papers=0;
String statement="";
try
{
statement="select no_of_papers from x_masterListOfCourses where course_id=" + course_id;
DB1.setStatement(statement);
ResultSet objRs=(ResultSet)DB1.result();
if(objRs.next())
{
no_of_papers=objRs.getInt("no_of_papers");
}
}
catch(Exception e)
{
out.print("error occured while executing the query:" + e);
}
try
{
String user_name=(String)session.getAttribute("user_name");
java.util.Date now=new java.util.Date();
java.sql.Date date=new java.sql.Date(now.getYear(),now.getMonth(),now.getDate());
String trainee_id="OL_" + course_id + "_" + user_name;
statement="select * from x_master_trainee_detail_online";
DB.setStatement(statement);
ResultSet objRsInsert=(ResultSet)DB.resultUpdate();
objRsInsert.next();
objRsInsert.updateString("trainee_id",trainee_id);
session.setAttribute("trainee_id",trainee_id);
objRsInsert.updateString("user_name",user_name);
objRsInsert.updateInt("is_registered",1);
objRsInsert.updateInt("is_paper1_tutorial_viewed",0);
objRsInsert.updateInt("is_paper2_tutorial_viewed",0);
objRsInsert.updateInt("is_paper3_tutorial_viewed",0);
objRsInsert.updateInt("is_paper4_tutorial_viewed",0);
objRsInsert.updateInt("is_paper5_tutorial_viewed",0);
objRsInsert.updateInt("is_attended_exam",0);
objRsInsert.updateInt("course_id",course_id);
objRsInsert.updateInt("paper1_no_of_attempts",0);
objRsInsert.updateInt("paper2_no_of_attempts",0);
objRsInsert.updateInt("paper3_no_of_attempts",0);
objRsInsert.updateInt("paper4_no_of_attempts",0);
objRsInsert.updateInt("paper5_no_of_attempts",0);
objRsInsert.updateInt("is_paper1_completed",0);
objRsInsert.updateInt("is_paper2_completed",0);
objRsInsert.updateInt("is_paper3_completed",0);
objRsInsert.updateInt("is_paper4_completed",0);
objRsInsert.updateInt("is_paper5_completed",0);
objRsInsert.updateInt("paper1_marks",0);
objRsInsert.updateInt("paper2_marks",0);
objRsInsert.updateInt("paper3_marks",0);
objRsInsert.updateInt("paper4_marks",0);
objRsInsert.updateInt("paper5_marks",0);
objRsInsert.updateDate("doe",date);
objRsInsert.updateInt("no_of_papers",no_of_papers);
objRsInsert.insertRow();
response.sendRedirect("course_step.jsp?result=Enrolled successfully.&course_id=" + course_id);

}
catch(Exception e)
{
out.print("error occured while inserting: " + e);
}
%>

sql table is as follows

Code:
-- phpMyAdmin SQL Dump
-- version 2.6.0-rc1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Mar 24, 2010 at 02:30 AM
-- Server version: 4.0.20
-- PHP Version: 5.0.1
--
-- Database: `elearning_datasource`
--

-- --------------------------------------------------------

--
-- Table structure for table `x_master_trainee_detail_online`
--

CREATE TABLE `x_master_trainee_detail_online` (
`trainee_id` varchar(25) NOT NULL default '',
`is_registered` int(10) NOT NULL default '0',
`is_attended_exam` int(10) NOT NULL default '0',
`is_successfully_completed` int(10) NOT NULL default '0',
`course_completed_date` date NOT NULL default '0000-00-00',
`total_marks` int(10) NOT NULL default '0',
`doe` date NOT NULL default '0000-00-00',
`user_name` varchar(25) NOT NULL default '',
`course_id` int(10) NOT NULL default '0',
`paper1_no_of_attempts` int(10) NOT NULL default '0',
`paper2_no_of_attempts` int(10) NOT NULL default '0',
`paper3_no_of_attempts` int(10) NOT NULL default '0',
`paper4_no_of_attempts` int(10) NOT NULL default '0',
`paper5_no_of_attempts` int(10) NOT NULL default '0',
`paper1_marks` int(10) NOT NULL default '0',
`paper2_marks` int(10) NOT NULL default '0',
`paper3_marks` int(10) NOT NULL default '0',
`paper4_marks` int(10) NOT NULL default '0',
`paper5_marks` int(10) NOT NULL default '0',
`paper1_completed_date` date NOT NULL default '0000-00-00',
`paper2_completed_date` date NOT NULL default '0000-00-00',
`paper3_completed_date` date NOT NULL default '0000-00-00',
`paper4_completed_date` date NOT NULL default '0000-00-00',
`paper5_completed_date` date NOT NULL default '0000-00-00',
`paper_id1` int(10) NOT NULL default '0',
`paper_id2` int(10) NOT NULL default '0',
`paper_id3` int(10) NOT NULL default '0',
`paper_id4` int(10) NOT NULL default '0',
`paper_id5` int(10) NOT NULL default '0',
`is_paper1_completed` int(10) NOT NULL default '0',
`is_paper2_completed` int(10) NOT NULL default '0',
`is_paper3_completed` int(10) NOT NULL default '0',
`is_paper4_completed` int(10) NOT NULL default '0',
`is_paper5_completed` int(10) NOT NULL default '0',
`paper1_appeared_on` date NOT NULL default '0000-00-00',
`paper2_appeared_on` date NOT NULL default '0000-00-00',
`paper3_appeared_on` date NOT NULL default '0000-00-00',
`paper4_appeared_on` date NOT NULL default '0000-00-00',
`paper5_appeared_on` date NOT NULL default '0000-00-00',
`is_paper1_tutorial_viewed` int(10) NOT NULL default '0',
`is_paper2_tutorial_viewed` int(10) NOT NULL default '0',
`is_paper3_tutorial_viewed` int(10) NOT NULL default '0',
`is_paper4_tutorial_viewed` int(10) NOT NULL default '0',
`is_paper5_tutorial_viewed` int(10) NOT NULL default '0',
`no_of_papers` int(10) NOT NULL default '0',
PRIMARY KEY (`trainee_id`)
) TYPE=MyISAM;

--
-- Dumping data for table `x_master_trainee_detail_online`
--
Can you tell me what is that error. Any kind of help will be appreciated. thanks
 
Misha Ver
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Viruthagiri Thirumalvalavan wrote:Guys i got file enroll.jsp while executing that i got java.lang.NullPointerException.


Stack Trace should give you an exact error location
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags.

And, putting java in a JSP page is a very poor practice. This is not activity that should be taking place in a JSP.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the second time you've been asked to UseCodeTags. We actually mean it--unformatted code is needlessly difficult to read. Make it easy for people to help you -- ShowSomeEffort.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34378
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another bad practice - having two try/catch blocks. If the first fails, do you want to continue?

As for the NullPointer, what line is it being thrown on? You can find out by removing code until it stops happening.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic