473,837 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delete table records using checkbox in jsp

15 New Member
hi,
i hav "java.lang.Null PointerExceptio n" 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.sq l.*"%>
<html>
<head>
<title>Admin Page</title>
<script language="javas cript">

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

}

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

}


</script>
</head>

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

<td width="14%">&nb sp;&nbsp;&nbsp; &nbsp;Date</td>
<td width="32%">Nam e</td>
<td width="40%">Ema il Id</td>
<td width="14%">Con tact No</td>

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

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


try
{
Class.forName(" com.mysql.jdbc. Driver");
con = DriverManager.g etConnection("j dbc:mysql://localhost:3306/ram","root","su n");
stmt = con.createState ment();

String qy = "select * from userinfofresher ";

rs = stmt.executeQue ry(qy);

while(rs.next() )
{
%>
<table width="95%">
<tr><td width="3%"><inp ut type="checkbox" name="chbox" value="<%=rs.ge tString(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.g etMessage());
}

%>

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

</head>

<body>


<%

String c[]= request.getPara meterValues("ch box");
out.println(c[0]);

Connection con = null;
Statement stmt = null;

try
{

Class.forName(" com.mysql.jdbc. Driver");
con = DriverManager.g etConnection("j dbc:mysql://localhost:3306/ram","root","su n");
stmt = con.createState ment();
for(String s:c)
{
String qy = "delete from userinfofresher where emailid='"+s+"' ";
stmt.executeUpd ate(qy);
out.println("Su ccessfully Deleted");
}

}
catch(Exception e)
{

out.println(e.g etMessage());
}
%>

</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_CHE CKS=0;
-- ----------------------------
-- Table structure for userinfofresher
-- ----------------------------
DROP TABLE IF EXISTS `userinfofreshe r`;
CREATE TABLE `userinfofreshe r` (
`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 `userinfofreshe r` VALUES ('RAMPRAKASH K A', 'ramprakash.jav a@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,Chen nai -74%', '', '', 'C,java/j2ee', 'HCL technologies,Am battur,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 `userinfofreshe r` VALUES ('ram', 'ramprakash_ka@ yahoo.co.in', '5454418745', '5,dsghjkghdjka fjf', 'gkjdflgkdfj', 'mvn', '54655646', '6,ssjkfhjhdfjj l', '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\nvcslmklgmdk lm\r\nvdfm,;dm\ r\nvmvd', 'jnmnjkgj', 'video game', '2009-2-12');
INSERT INTO `userinfofreshe r` VALUES ('ram', 'ramprakash_kas @yahoo.co.in', '5454418745', '5,dsghjkghdjka fjf', 'gkjdflgkdfj', 'mvn', '54655646', '6,ssjkfhjhdfjj l', '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\nvcslmklgmdk lm\r\nvdfm,;dm\ r\nvmvd', 'jnmnjkgj', 'video game', '2009-2-11');
INSERT INTO `userinfofreshe r` VALUES ('ram', 'ramprakash_k@y ahoo.co.in', '5454418745', '5,dsghjkghdjka fjf', 'gkjdflgkdfj', 'mvn', '54655646', '6,ssjkfhjhdfjj l', '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\nvcslmklgmdk lm\r\nvdfm,;dm\ r\nvmvd', 'jnmnjkgj', 'video game', '2009-2-09');
INSERT INTO `userinfofreshe r` VALUES ('ram', 'ramprakash_a@y ahoo.co.in', '5454418745', '5,dsghjkghdjka fjf', 'gkjdflgkdfj', 'mvn', '54655646', '6,ssjkfhjhdfjj l', '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\nvcslmklgmdk lm\r\nvdfm,;dm\ r\nvmvd', 'jnmnjkgj', 'video game', '2009-2-09');
INSERT INTO `userinfofreshe r` VALUES ('ram', 'ramprakash@yah oo.co.in', '5454418745', '5,dsghjkghdjka fjf', 'gkjdflgkdfj', 'mvn', '54655646', '6,ssjkfhjhdfjj l', '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\nvcslmklgmdk lm\r\nvdfm,;dm\ r\nvmvd', 'jnmnjkgj', 'video game', '2009-2-08');
INSERT INTO `userinfofreshe r` 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,Chen nai -74%', '2005-2007 Master of Computer Science Engineering in St.Joseph?s Engineering College, Anna University,Chen nai -70%', '', 'b fhytyhj', 'nghjdtj', 'ghmj', 'bdfbhfhfhfrhrh ', 'hfhdtyjtyhjtjt j2005-2007 Master of Computer Science Engineering in St.Joseph?s Engineering College, Anna University,Chen nai -70%2005-2007 Master of Computer Science Engineering in St.Joseph?s Engineering College, Anna University,Chen nai -70%2005-2007 Master of Computer Science Engineering in St.Joseph?s Engineering College, Anna University,Chen nai -70%', 'cmjmkcfku', 'jghjg', '2009-2-05');
Mar 3 '09 #1
13 26945
debasisdas
8,127 Recognized Expert Expert
Question moved to Java forum.
Mar 5 '09 #2
r035198x
13,262 MVP
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 Recognized Expert Contributor
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 Recognized Expert MVP
@debasisdas
Trash belongs in the trash bin, thank you.

kind regards,

Jos
Mar 5 '09 #5
ramprakashjava
15 New Member
@chaarmann
/* here i listed line number of error*/
java.lang.NullP ointerException
org.apache.jsp. deletepage_jsp. _jspService(del etepage_jsp.jav a:57)
org.apache.jasp er.runtime.Http JspBase.service (HttpJspBase.ja va:94)
javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:802)
org.apache.jasp er.servlet.JspS ervletWrapper.s ervice(JspServl etWrapper.java: 324)
org.apache.jasp er.servlet.JspS ervlet.serviceJ spFile(JspServl et.java:292)
org.apache.jasp er.servlet.JspS ervlet.service( JspServlet.java :236)
javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:802)
Mar 6 '09 #6
r035198x
13,262 MVP
Did you make the code changes suggested?
Mar 6 '09 #7
chaarmann
785 Recognized Expert Contributor
@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
ramprakashjava
15 New Member
s i grabbed it that line is
out.println(c[0]);
Mar 6 '09 #9
r035198x
13,262 MVP
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

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

Similar topics

2
3989
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 table again. So please help, I just wanted to delete the records rather than dropping the table completely and start over again.. Thanks Jack
2
4996
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 fields (vehicleID, BattID, and ChgHrs). VehicleID and BattID are a TEXT datatype and ChrHrs are a number(long int.) datatype. Since records to be imported can have duplicate records of the composite key I need to clean all but one of the...
1
3998
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 need to turn it into a Form to be able to capture whats been checked but I would appreciate any guidance. Most of the code I am using is from a solution a co-worker wrote for another solution and I learning by using it as a guide/example if...
3
5934
madhoriya22
by: madhoriya22 | last post by:
I have solved the problem
7
6431
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 may give some code, it will be better for me thanks..
5
14409
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 predefined recordset from the tblStaticAllForecast table LockSQL = "SELECT * FROM tblStaticAllForecast WHERE" & _ " DivisionIDFK = " & Val(Me.cboDivision.Value) & _
6
5938
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 index it showed error as unique key violation. So i want to delete duplicate records for col1,col2,col3,col4 combination. How can i delete the duplicate records from this large table?
1
4316
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 displaying the records entered in the table.... <?php $con = mysql_connect("localhost","root","root"); if (!$con) { die('Could not connect: ' . mysql_error());
0
995
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 help me... I am new in vb and not very good on it. Im using vb 6 and acess as database. Here is the source code: Private Sub ComHapusGuru_Click(Index As Integer) Dim iHapus As Integer Adodc3.RecordSource = "SELECT * FROM Guru" iHapus =...
0
9830
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10615
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10263
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9390
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6989
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5664
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5842
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4469
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3122
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.