473,416 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Delete table records using checkbox in jsp

hi,
i hav "java.lang.NullPointerException" error while Deleting table records using checkbox in jsp here i enclosed files help quickly plzzz..
Regards
Ramprakash

/*Adminpage.jsp*/
<%@ page language="java" import="java.sql.*"%>
<html>
<head>
<title>Admin Page</title>
<script language="javascript">

function validation()
{
var count=0;
for(vari=0;i<admin.chbox.length;i++)
{
if(admin.chbox[i].checked)
{
count++;
}

}

if(count==0)
{
alert("check the messages to delete & u had limited msg");
//document.msgchbox.checkbox.focus();
return false;
}
else
{
return true;
}

}


</script>
</head>

<body>
<form name="admin" method="post" action="deletepage.jsp" onClick="return validation()">
<h2 align="center">Freshers Table Records</h2>
<div align="right"><input type="submit" value=" DELETE "/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</div>
<div>
<table border="3" width="95%">
<tr>

<td width="14%">&nbsp;&nbsp;&nbsp;&nbsp;Date</td>
<td width="32%">Name</td>
<td width="40%">Email Id</td>
<td width="14%">Contact No</td>

</tr></table>
</div>
</form>
<%

Connection con = null;
Statement stmt = null;
ResultSet rs=null;


try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/ram","root","sun");
stmt = con.createStatement();

String qy = "select * from userinfofresher";

rs = stmt.executeQuery(qy);

while(rs.next())
{
%>
<table width="95%">
<tr><td width="3%"><input type="checkbox" name="chbox" value="<%=rs.getString(3)%>"/></td>
<td width="12%"><%=rs.getString(33)%></td>
<td width="33%"><%=rs.getString(1)%></td>
<td width="41%"><%=rs.getString(2)%></td>
<td width="15%"><%=rs.getString(3)%></td>
</tr></table>
<%
}

}
catch(Exception e)
{
out.println(e.getMessage());
}

%>

</body>
</html>
/*deletepage.jsp*/
<%@ page language="java" import="java.sql.*"%>
<html>
<head>
<title>Delete page</title>

</head>

<body>


<%

String c[]= request.getParameterValues("chbox");
out.println(c[0]);

Connection con = null;
Statement stmt = null;

try
{

Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/ram","root","sun");
stmt = con.createStatement();
for(String s:c)
{
String qy = "delete from userinfofresher where emailid='"+s+"' ";
stmt.executeUpdate(qy);
out.println("Successfully Deleted");
}

}
catch(Exception e)
{

out.println(e.getMessage());
}
%>

</body>
</html>
/*db file */
/*
MySQL Data Transfer
Source Host: localhost
Source Database: ram
Target Host: localhost
Target Database: ram
Date: 3/2/2009 4:03:02 PM
*/

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for userinfofresher
-- ----------------------------
DROP TABLE IF EXISTS `userinfofresher`;
CREATE TABLE `userinfofresher` (
`name` varchar(255) NOT NULL,
`emailid` varchar(255) NOT NULL,
`contno` varchar(255) NOT NULL,
`tds` varchar(255) NOT NULL,
`ta` varchar(255) NOT NULL,
`tc` varchar(255) NOT NULL,
`tz` varchar(255) NOT NULL,
`pds` varchar(255) NOT NULL,
`pa` varchar(255) NOT NULL,
`pc` varchar(255) NOT NULL,
`pz` varchar(255) NOT NULL,
`fathersname` varchar(255) NOT NULL,
`sex` varchar(255) NOT NULL,
`dob` varchar(255) NOT NULL,
`age` varchar(255) NOT NULL,
`bloodgroup` varchar(255) NOT NULL,
`nationality` varchar(255) NOT NULL,
`matrialstatus` varchar(255) NOT NULL,
`language` varchar(255) NOT NULL,
`sslc` varchar(255) NOT NULL,
`hsc` varchar(255) NOT NULL,
`degree1` varchar(255) NOT NULL,
`degree2` varchar(255) NOT NULL,
`degree3` varchar(255) NOT NULL,
`degree4` varchar(255) NOT NULL,
`software` varchar(255) NOT NULL,
`ipt` varchar(255) NOT NULL,
`aoi` varchar(255) NOT NULL,
`projtitle` varchar(255) NOT NULL,
`projdes` longtext NOT NULL,
`ach` varchar(255) NOT NULL,
`hobby` varchar(255) NOT NULL,
`date` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- ----------------------------
-- Records
-- ----------------------------
INSERT INTO `userinfofresher` VALUES ('RAMPRAKASH K A', 'ramprakash.java@gmail.com', ' 9787818096', 'No 8,First cross st', 'Annanagar West', 'Chennai', '600078', 'No 5/E, cross st', 'West pillaiyar koil st', 'Trichy', '638478', 'Arun K P', 'Male', '03nov1982', '21', 'O+ve ', 'Indian', 'Unmarried', 'Tamil,English', '1997-2000 S.S.L.C (State Board )Govt High School,Karur -87%', ' 2000-2002 XII Standard (State Board)Govt Higher Secondary School,Karur -82%', '2002-2005 Dipoma in Computer Technology Govt Polytechnic College,Karur -90%', '2002-2005 Bachelor of Computer Science Engineering in St.Joseph?s Engineering College, Anna University,Chennai -74%', '', '', 'C,java/j2ee', 'HCL technologies,Ambattur,Chennai.', 'web Developement', 'Vendor Information Management System.', 'The VIMS deals with the Online Ship store management system.It is an bridge between the supplier and the ship.The VIMS deals with the Online Ship store management system.It is an bridge between the supplier and the ship.The VIMS deals with the Online Ship store management system.It is an bridge between the supplier and the ship.The VIMS deals with the Online Ship store management system.It is an bridge between the supplier and the ship.The VIMS deals with the Online Ship store management system.It is an bridge between the supplier and the ship.The VIMS deals with the Online Ship store management system.It is an bridge between the supplier and the ship.', 'Won the First Prize for Paper Presentation held on Sankara College-Coimbatore', 'Reading books,Playing cricket', '2009-2-13');
INSERT INTO `userinfofresher` VALUES ('ram', 'ramprakash_ka@yahoo.co.in', '5454418745', '5,dsghjkghdjkafjf', 'gkjdflgkdfj', 'mvn', '54655646', '6,ssjkfhjhdfjjl', 'lkbv', 'ijhgjkdfh', '624654', 'kdfjnbio', 'male', '03nov1992', '23', 'b+ve', 'indian', 'single', 'nmkgnkg', '1997-2000 S.S.L.C (State Board )Govt High School,Karur -87%', '2000-2002 XII Standard (State Board)Govt Higher Secondary School,Karur -82%', '2002-2005 Dipoma in Computer Technology Govt Polytechnic College,Karur -90%', '', '', '', 'c,java', 'bknjknsghitjkn dfgkjhdfkghjk', 'mgmkjgl', 'automatic alaram', 'bvdbdnm n m\r\nsdnslfnksl\r\nvcslmklgmdklm\r\nvdfm,;dm\r\nvm vd', 'jnmnjkgj', 'video game', '2009-2-12');
INSERT INTO `userinfofresher` VALUES ('ram', 'ramprakash_kas@yahoo.co.in', '5454418745', '5,dsghjkghdjkafjf', 'gkjdflgkdfj', 'mvn', '54655646', '6,ssjkfhjhdfjjl', 'lkbv', 'ijhgjkdfh', '624654', 'kdfjnbio', 'male', '03nov1992', '23', 'b+ve', 'indian', 'single', 'nmkgnkg', '1997-2000 S.S.L.C (State Board )Govt High School,Karur -87%', '2000-2002 XII Standard (State Board)Govt Higher Secondary School,Karur -82%', '2002-2005 Dipoma in Computer Technology Govt Polytechnic College,Karur -90%', '', '', '', 'c,java', 'bknjknsghitjkn dfgkjhdfkghjk', 'mgmkjgl', 'automatic alaram', 'bvdbdnm n m\r\nsdnslfnksl\r\nvcslmklgmdklm\r\nvdfm,;dm\r\nvm vd', 'jnmnjkgj', 'video game', '2009-2-11');
INSERT INTO `userinfofresher` VALUES ('ram', 'ramprakash_k@yahoo.co.in', '5454418745', '5,dsghjkghdjkafjf', 'gkjdflgkdfj', 'mvn', '54655646', '6,ssjkfhjhdfjjl', 'lkbv', 'ijhgjkdfh', '624654', 'kdfjnbio', 'male', '03nov1992', '23', 'b+ve', 'indian', 'single', 'nmkgnkg', '1997-2000 S.S.L.C (State Board )Govt High School,Karur -87%', '2000-2002 XII Standard (State Board)Govt Higher Secondary School,Karur -82%', '2002-2005 Dipoma in Computer Technology Govt Polytechnic College,Karur -90%', '', '', '', 'c,java', 'bknjknsghitjkn dfgkjhdfkghjk', 'mgmkjgl', 'automatic alaram', 'bvdbdnm n m\r\nsdnslfnksl\r\nvcslmklgmdklm\r\nvdfm,;dm\r\nvm vd', 'jnmnjkgj', 'video game', '2009-2-09');
INSERT INTO `userinfofresher` VALUES ('ram', 'ramprakash_a@yahoo.co.in', '5454418745', '5,dsghjkghdjkafjf', 'gkjdflgkdfj', 'mvn', '54655646', '6,ssjkfhjhdfjjl', 'lkbv', 'ijhgjkdfh', '624654', 'kdfjnbio', 'male', '03nov1992', '23', 'b+ve', 'indian', 'single', 'nmkgnkg', '1997-2000 S.S.L.C (State Board )Govt High School,Karur -87%', '2000-2002 XII Standard (State Board)Govt Higher Secondary School,Karur -82%', '2002-2005 Dipoma in Computer Technology Govt Polytechnic College,Karur -90%', '', '', '', 'c,java', 'bknjknsghitjkn dfgkjhdfkghjk', 'mgmkjgl', 'automatic alaram', 'bvdbdnm n m\r\nsdnslfnksl\r\nvcslmklgmdklm\r\nvdfm,;dm\r\nvm vd', 'jnmnjkgj', 'video game', '2009-2-09');
INSERT INTO `userinfofresher` VALUES ('ram', 'ramprakash@yahoo.co.in', '5454418745', '5,dsghjkghdjkafjf', 'gkjdflgkdfj', 'mvn', '54655646', '6,ssjkfhjhdfjjl', 'lkbv', 'ijhgjkdfh', '624654', 'kdfjnbio', 'male', '03nov1992', '23', 'b+ve', 'indian', 'single', 'nmkgnkg', '1997-2000 S.S.L.C (State Board )Govt High School,Karur -87%', '2000-2002 XII Standard (State Board)Govt Higher Secondary School,Karur -82%', '2002-2005 Dipoma in Computer Technology Govt Polytechnic College,Karur -90%', '', '', '', 'c,java', 'bknjknsghitjkn dfgkjhdfkghjk', 'mgmkjgl', 'automatic alaram', 'bvdbdnm n m\r\nsdnslfnksl\r\nvcslmklgmdklm\r\nvdfm,;dm\r\nvm vd', 'jnmnjkgj', 'video game', '2009-2-08');
INSERT INTO `userinfofresher` VALUES ('fsdfa', 'vdvtgert', '4536767', 'bfgbhgfhf', 'bn fghf', 'fngfn fnj', '76766', 'njfjfh', 'fjgj', 'nmghmjg', '25678', 'vcgrsh', 'fnjgj', 'xcfgjgtj', 'cgmjgj', 'cgnmgh', 'n cvnn', 'jyjtyjy', 'njghnjg', '1997-2000 S.S.L.C (State Board )Govt High School,Karur -87%', '2000-2002 XII Standard (State Board)Govt Higher Secondary School,Karur -82%', '2002-2005 Dipoma in Computer Technology Govt Polytechnic College,Karur -90%', '2002-2005 Bachelor of Computer Science Engineering in St.Joseph?s Engineering College, Anna University,Chennai -74%', '2005-2007 Master of Computer Science Engineering in St.Joseph?s Engineering College, Anna University,Chennai -70%', '', 'b fhytyhj', 'nghjdtj', 'ghmj', 'bdfbhfhfhfrhrh', 'hfhdtyjtyhjtjtj2005-2007 Master of Computer Science Engineering in St.Joseph?s Engineering College, Anna University,Chennai -70%2005-2007 Master of Computer Science Engineering in St.Joseph?s Engineering College, Anna University,Chennai -70%2005-2007 Master of Computer Science Engineering in St.Joseph?s Engineering College, Anna University,Chennai -70%', 'cmjmkcfku', 'jghjg', '2009-2-05');
Mar 3 '09 #1
13 26886
debasisdas
8,127 Expert 4TB
Question moved to Java forum.
Mar 5 '09 #2
r035198x
13,262 8TB
1.) Use code tags when posting code.
2.) Move all that database connection code away from the JSP into some utility class or servlet. JSPs are for displaying data only.
3.) Check whether c[] is null or not before you try to do anything with it.
Mar 5 '09 #3
chaarmann
785 Expert 512MB
1.) Please list line number of your error.
2.) Please change your program in a way that you check for EVERY possible value of the called functions first! For example:

Your code:
Expand|Select|Wrap|Line Numbers
  1. String c[]= request.getParameterValues("chbox");
  2. out.println(c[0]); 
  3.  
Change to:
Expand|Select|Wrap|Line Numbers
  1. String c[]= request.getParameterValues("chbox");
  2. if (c != null && c.length != 0) out.println(c[0]);
  3. else out.println("Something went wrong! I tried to access a non-existing array or the first element of an existing array that is not there!");
  4.  
Mar 5 '09 #4
JosAH
11,448 Expert 8TB
@debasisdas
Trash belongs in the trash bin, thank you.

kind regards,

Jos
Mar 5 '09 #5
@chaarmann
/* here i listed line number of error*/
java.lang.NullPointerException
org.apache.jsp.deletepage_jsp._jspService(deletepa ge_jsp.java:57)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
Mar 6 '09 #6
r035198x
13,262 8TB
Did you make the code changes suggested?
Mar 6 '09 #7
chaarmann
785 Expert 512MB
@ramprakashjava
that's a beginning, but not enough. You should be aware that every jsp-page is converted to java and stored in Apaches "work" directory. The line number listed above references to the line inside this java file and not to a line number in the original jsp.
In your case, your file "deletepage.jsp" is converted to "deletepage_jsp.java". The error is in line 57 of "deletepage_jsp.java" that you can find in "work" directory.

Please just grab the line number 57 from it and list it here.
Mar 6 '09 #8
s i grabbed it that line is
out.println(c[0]);
Mar 6 '09 #9
r035198x
13,262 8TB
This is turning out to be a rather pointless thread. Did you make all the suggested code changes?
There is no point in posting suggestions if you are just ignoring them.
Mar 6 '09 #10
here i eclosed few lines thats plz check it

out.write("\r\n");
out.write("<html>\r\n");
out.write("<head>\r\n");
out.write("<title>Delete page</title>\r\n");
out.write("\r\n");
out.write("</head>\r\n");
out.write("\r\n");
out.write("<body>\r\n");
out.write(" \r\n");
out.write("\r\n");
out.write(" ");



String c[]= request.getParameterValues("chbox");
out.println(c[0]);



Connection con = null;
Statement stmt = null;

try
{

Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/ram","root","admin");
stmt = con.createStatement();
for(String s:c)
Mar 6 '09 #11
r035198x
13,262 8TB
Read the replies that have already been posted. Why are you ignoring them?
Mar 6 '09 #12
chaarmann
785 Expert 512MB
@ramprakashjava
Ok, so you know that it's crashing because the array c[] is null or empty.
If you have checkboxes and you don't check them, the values are not passed, so the array that you want to get is null.
So c[]=request.getParameterValues("chbox"); gives you exactly that null array in this case.

You cannot access an array that's not there. (i.e. that is null)
You cannot access the first element of an array if the array has no elements. (i.e. accessing c[0])
That's what I mean with:
You have to care about ALL possible values a function might return in your code. I mean every function, especially including the function request.getParameterValues().

So please apply my code changes listed above. I will list them again here:
Expand|Select|Wrap|Line Numbers
  1. String c[]= request.getParameterValues("chbox"); 
  2. if (c != null && c.length != 0) out.println(c[0]); 
  3. else out.println("Something went wrong! I tried to access a non-existing array or the first element of an existing array that is not there!"); 
  4.  
(and write the rest of the code in your program accordingly)

Then your program will work bugfree.
Mar 9 '09 #13
r035198x
13,262 8TB
A relevant read.
Mar 10 '09 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jacky Luk | last post by:
Hi, I can't seem to find a way to delete all records of a table. I created my tables in MySQL Query Browser, then fill them up with VC++, but some records were incorrect, And I had to recreate the...
2
by: ms | last post by:
Access 2000: I am trying to delete duplicate records imported to a staging table leaving one of the duplicates to be imported into the live table. A unique record is based on a composite key of 3...
1
by: bigabytes | last post by:
I'm just learning PHP (extreme novice) and I'm struggling with deleting records using a checkbox included within each row. I have a few idea but I'm not sure if my thoughts are correct. I think I...
3
madhoriya22
by: madhoriya22 | last post by:
I have solved the problem
7
by: mukeshrasm | last post by:
hello everyone I want to delete the selected records from database using checkbox. whch is generated dyanamically and checkbox is also generated dynamically,using php. so please help me. if you...
5
kcdoell
by: kcdoell | last post by:
Hello: I am trying to write a code that will delete all records found in my DAO recordset Below is the code I have so far: 'Procdure to give the user the ability to delete all records 'for a...
6
by: Dilip1983 | last post by:
Hi All, I want to delete duplicate records from a large table. There is one index(INDEX_U1) on 4 columns(col1,col2,col3,col4) which is in unusable state. First of all when i tried to rebuild...
1
by: puneetmca | last post by:
hi...this code of deleting a record from database using checkbox is not working...echo "<td>$row</td>; echo "<td>$row</td>"; echo "<td>$row....these lines print as it is...rather then...
0
by: salhana | last post by:
I have problem to solve this. I want to delete all the records in one table. but it always get error says, "run time error '91', object variable or with block variable not set". Please some body...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.