473,396 Members | 1,864 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.

Show contents of database using Show.jsp

here is the code:-
Expand|Select|Wrap|Line Numbers
  1. <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <%
  2. String path = request.getContextPath();
  3. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  4. %> <html> <head> <title>Assessment Call List</title> <script language="javascript">
  5.  
  6. function validation()
  7. {
  8. var count=0;
  9. for(vari=0;i<admin.chbox.length;i++)
  10. {
  11. if(admin.chbox[i].checked)
  12. {
  13. count++;
  14. }
  15.  
  16. }
  17.  
  18. if(count==0)
  19. {
  20. alert("check the messages to delete & u had limited msg");
  21. //document.msgchbox.checkbox.focus();
  22. return false;
  23. }    
  24. else
  25. {
  26. return true;
  27. }
  28.  
  29. }
  30.  
  31.  
  32. </script> </head> <body> <form name="admin" method="post" action="http://bytes.com/Delete.jsp" onClick="return validation()"> <h2 align="center"><font color="800000"></>Assessment Call List</font></h2> <div align="right"><input type="submit" value=" DELETE "/>********& nbsp;*****
  33. </div> <div> <table border="3" width="95%"> <%@page import="java.sql.DriverManager"%> <%@page import="java.sql.ResultSet"%> <%@page import="java.sql.Statement"%> <%@page import="java.sql.Connection"%> <%@page import="com.list.*"%> <% 
  34.  
  35. Connection con = null;
  36. Statement stmt = null;
  37. ResultSet rs=null;
  38. %> <tr>  <td width="10%"></td> <td width="32%">Names</td> <td width="40%">Date of Assessment</td>  </tr></table> </div> </form> <%
  39. try
  40. //Class.forName("com.mysql.jdbc.Driver");
  41. //con = DriverManager.getConnection("jdbc:mysql://localhost:3306/ram","root","sun");
  42. //stmt = con.createStatement();
  43. stmt=DB.getConnection().createStatement();
  44. String qy = "select * from Edate"; 
  45.  
  46. rs = stmt.executeQuery(qy);
  47.  
  48. while(rs.next())
  49. {
  50. String  NAMES=rs.getString(1);
  51. String  DATES=rs.getString(2);
  52. %> <table width="95%"> <tr><td width="12%"><input type="checkbox" name="chbox" value="<%=rs.getString(0)%>"/></td>  <td width="33%"><%=rs.getString(1)%></td> <td width="41%"><%=rs.getString(2)%></td>  </tr></table> <% 
  53. }
  54.  
  55. }
  56. catch(Exception e)
  57. {
  58. out.println(e.getMessage());
  59. }
  60.  
  61. %> </body> </html>
Output:-

Invalid Column Index
Jun 17 '14 #1
1 1325
chaarmann
785 Expert 512MB
Can you please post the structure of the table you are querying?
Maybe it only has 2 rows instead of 3, that would explain the "invalid column index".

My advise: read each line of your code and ask yourself for its purpose, slowly! I think you are too much in a hurry. Why? You are defining NAMES and DATES (see line 51), but you are not using then in the next line but instead again using rs.getString(i) with indexes i 0, 1 and 2.
Second, you write to all (!) users: "check the messages to delete & u had limited msg" (line 20) That is not correct English, but hurry-up SMS chat. "You" = "u", "and"="&", "msg" = message", no dot at end. What's the meaning of "and you had limited message" anyway?

Also your string "********& nbsp;*****" will not work as expected. (delete empty space after &)

"NAMES" and "DATES" are names not adhering to the common coding style. You only should use all-capital-letter names for constants.

General advice:
Use Model-View-Controller (MVC). Put only the HTML-generation inside your JSP, but put the businness logic (the database access) in a servlet instead.
Use Stylesheets. Things like your "<font color="800000">" are bad. Use color names instead of numbers.: 800000 is maroon.
Do not print the error message on the browser window (line 59). Hackers like internal program structure infos, but a user cannot do anything with it. Print it into a log and show an error page with administrator contact info instead.
Jun 18 '14 #2

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

Similar topics

6
by: Jeff Sandler | last post by:
I have a database I created in mySQL. I've been entering data every day into the database using a Java application that I wrote. The database and the Java program are on the same Win 98 SE...
9
by: Peter | last post by:
Hello£¬everyone, My program will collect a testing machine's data ,save the data and deal with the data everyday. I want to use vb.net to create database, add and delete tables or modify the...
0
by: wingtong | last post by:
Our Deltek accounting software will be migrating from a Jet database to a SQL express database. In the past, when using the Jet database, I have been able to make a copy of the JET database to my...
3
by: Vardhini Gold | last post by:
Hi, I am Vardhini. The project that I am working for is a web based application. I use ASP.2.0/ VB.NET (Visual studio 2005). Kindly help me in importing excel contents to SQL Database using...
9
by: christopher_board | last post by:
Hi all. I am trying to connect to a MySQL Database using PHP on a local machine using locahost. I am using the following code <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass =...
3
by: abhishek1234321 | last post by:
I have a form at http://www.vtuhub.com/w.html which shows results if a proper roll number is entered... the results are fetched from http://results.vtu.ac.in site and only the table is shown... now i...
4
by: shinypenny | last post by:
Hello all, I am trying to use PHP to pull information from a mySQL database, as well as offer an "Add More" button through the use of JavaScript. I'm able to put the new information into the...
1
by: pallabpal87 | last post by:
Hi! I am trying to insert a record in sql database using vb.net dataadapter, datatable, and datarow features. I use the following code. But it show me an error.(Object reference not set to an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...

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.