473,396 Members | 1,990 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,396 software developers and data experts.

Select checkbox for exactly one record

I hav a jsp page whch dynamically displays the records from database into table. On the left side of each row in a table i use checkbox for users to select for deleting single/multiple records from database.. if database contains muliple records i can easily check the checkboxes of required rows in a table and delete thm from database.. But i can't select a checkbox in a table if database contains exactly one record..
Help me plz.. it's urgent..

Thank u..
Jan 7 '12 #1
5 2210
Rabbit
12,516 Expert Mod 8TB
It would help to see the code
Jan 8 '12 #2
pcdelform

Expand|Select|Wrap|Line Numbers
  1. <%@ page language="java" import="java.sql.*"%>
  2. <% Class.forName("oracle.jdbc.driver.OracleDriver"); %>
  3. <html>
  4. <head>
  5. <title>PC Deletion Page</title>
  6. <script language="javascript">
  7.  
  8. function validation()
  9. {
  10. var count=0;
  11. for(var i=0;i<del.chbox.length;i++)
  12. {
  13. if(del.chbox[i].checked)
  14. {
  15. count++;
  16. }
  17.  
  18. }
  19.  
  20. if(count==0)
  21. {
  22. return false;
  23. else
  24. {
  25. return true;
  26. }
  27.  
  28. }
  29.  
  30.  
  31. </script>
  32. </head>
  33. <style type="text/css">@import url("style.css");</style>
  34. <body>
  35. <form name="del" method="post" action="pcdelprocess.jsp" onClick="return validation()">
  36. <h2 align="center">PC Details Table</h2></br></br></br>
  37. <% 
  38. try {
  39. Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@10.1.223.151:1521:ERPDVP","td_edc","td_edc");
  40. PreparedStatement ps=conn.prepareStatement("select * from pc_data order by asset_id");
  41. ResultSet rs=ps.executeQuery();
  42. %>
  43. <center><table border="1">
  44. <tr>
  45.     <th>ASSETID</th><th>PLANT</th><th>LOCATION</th><th>DEPARTMENT</th><th>IP ADDR</th><th>USERNAME</th><th>EMP ID</th><th>EMAIL ID</th><th>SL NO</th><th>TYPE</th><th>MAKE</th><th>MODEL</th><th>PROCESSOR</th><th>SPEED</th><th>RAM</th><th>HDD</th><th>EXT STORAGE</th><th>OS</th><th>WARRANTY</th><th>CDE</th><th>REMARKS</th>
  46. </tr>
  47. <%
  48. while(rs.next())
  49. {
  50. %> 
  51.  
  52. <tr>
  53.     <td><input type="checkbox" name="chbox" value="<%=rs.getString(1)%>" checked><%=rs.getString(1)%></td><td><%=rs.getString(2)%></td><td><%=rs.getString(3)%></td><td><%=rs.getString(4)%></td><td><%=rs.getString(5)%></td><td><%=rs.getString(6)%></td><td><%=rs.getString(7)%></td><td><%=rs.getString(8)%></td><td><%=rs.getString(9)%></td><td><%=rs.getString(10)%></td><td><%=rs.getString(11)%></td><td><%=rs.getString(12)%></td><td><%=rs.getString(13)%></td><td><%=rs.getString(14)%></td><td><%=rs.getString(15)%></td><td><%=rs.getString(16)%></td><td><%=rs.getString(17)%></td><td><%=rs.getString(18)%></td><td><%=rs.getString(19)%></td><td><%=rs.getString(20)%></td><td><%=rs.getString(21)%></td>
  54. </tr>
  55.  
  56. <% 
  57. }
  58.  
  59. }
  60. catch(Exception e)
  61. {
  62. out.println(e.getMessage());
  63. }
  64.  
  65. %>
  66. </table></center><br/><br/>
  67. <center><input type="submit" value=" DELETE "/></center>
  68.  
  69. </form>
  70. </body>
  71. </html>
  72.  
pcdelprocess

Expand|Select|Wrap|Line Numbers
  1. <%@ page language="java" import="java.sql.*"%>
  2. <% Class.forName("oracle.jdbc.driver.OracleDriver"); %>
  3. <html>
  4. <head>
  5. <title>Delete page</title>
  6.  
  7. </head>
  8.  
  9. <body>
  10.  
  11.  
  12. <% 
  13. try
  14. String s="";
  15. String d[]= request.getParameterValues("chbox");
  16.  
  17.  
  18.  
  19. if(d!=null)
  20. {
  21.     if(d.length==1)
  22.     {
  23.         s="'"+d[0]+"'";
  24.         out.println(s);
  25.     }
  26.     else
  27.     {
  28.         for(int i=0;i<d.length;i++)
  29.         {
  30.             s+="'"+d[i]+"'";
  31.             if(i<d.length-1)
  32.             {
  33.                 s+=",";
  34.             }
  35.         }
  36.         out.println(s);
  37.     }
  38. }
  39.  
  40.  
  41. Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@10.1.223.151:1521:ERPDVP","td_edc","td_edc");
  42. Statement stmt = conn.createStatement();
  43. String qy = "delete from pc_data where asset_id in("+s+") "; 
  44. stmt.executeUpdate(qy);
  45.  
  46. Statement st = conn.createStatement();
  47. String qy1= "delete from id_data1 where asset_id in("+s+") "; 
  48. st.executeUpdate(qy1);
  49. out.println("Successfully Deleted");
  50.  
  51. }
  52. catch(Exception e)
  53. {
  54.  
  55. out.println(e.getMessage());
  56. }
  57. %>
  58.  
  59. </body>
  60. </html>
Jan 8 '12 #3
Rabbit
12,516 Expert Mod 8TB
You can't select the checkbox? Or do you mean the server side script doesn't delete the record?
Jan 9 '12 #4
sir,
I can't select a check box if table contains only one record..
Jan 10 '12 #5
Rabbit
12,516 Expert Mod 8TB
Unless you've disabled the checkbox, and I see nothing to indicate that is the case, there's nothing that will prevent it from being clickable. So at this point I have no idea what you're talking about.

Perhaps if you posted some screenshots illustrating your point, that can clear things up.
Jan 10 '12 #6

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

Similar topics

3
by: Earl Teigrob | last post by:
I am considering writing a Class that Selects, Adds, Updates and Deletes Nodes in an XML File but do not what to reinvent the wheel. (See XML file below) That data format would emulate records...
4
by: Henry | last post by:
Dear all, I am now designing a table for storing inventory of servers in a DB2 DB. However, I am new to SQL and would like to seek advice whether the design could work as expect with DB2 SQL. ...
19
by: Barry Edmund Wright | last post by:
This simple stupid thing has me stumped! The cursor is on a record in a datasheet. How do I select that record (highlight) like I would if I clicked on the Record Selector using VBA. Regards....
6
by: Robin S. | last post by:
Originally I wanted a list box which selects which record is the current one within the same form. Easy enough until Access takes a dump when one is deleted and then someone tries to select it in...
8
by: find clausen | last post by:
qqq = GetCookie("whatever"); How do I select a chekbox in a form if qqq = yes TIA -- find clausen press photos from denmark www.photopress.dk
2
by: ASAP | last post by:
there is a checkbox in every row of a table. i need to check the checkbox on click of the corresponding row and vice -versa. means on again clicking of the same row it should get delected.
1
by: inamul | last post by:
I want to select CheckBox based on data retrieved from mysql database table. Could anyone show me the simple way of doing it. Data store in table under colum "sectionOfInterest" is shown below...
2
by: tvnaidu | last post by:
Why firefox doesn't remember userid and password eventhough I select checkbox "Remeber my login on this computer"?
1
by: Rodney Ferguson | last post by:
Hi, I'm programming a questionnaire but I'm having trouble with some checkboxes. I would like to have the user select or deselect the checkbox by clicking on the table cell that it is in. ...
1
by: David Patz | last post by:
Hi, Im currently building a database for users to edit or manipulate train maintanence parts. For one of my forms - I display the inactive parts in stock. I've designed the form to have a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
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,...

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.