File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Kindly help me with this checkbox issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Kindly help me with this checkbox issue" Watch "Kindly help me with this checkbox issue" New topic
Author

Kindly help me with this checkbox issue

nash avin
Ranch Hand

Joined: Nov 18, 2004
Posts: 45
Hi all,

Firstly I would like t o thank this very helpful forum.I have one more question regarding checkboxes.

/*courses.jsp*/

In my courses.jsp which connects to an MS Access database I have something like this...

<INPUT TYPE=CHECKBOX NAME="COURSES" VALUE="rs.getString("course")"><%out.print(rs.getString("course"));%></td>

/*courses.jsp*/

This is coming from the database.

In my servlet code i have this in the doPost method.

/*CheckBoxServlet*/ PS : This servlet is not connected to the database..


/*CheckBoxServlet*/


/* OUTPUT */

I have checked 5 check boxes

Checkbox values rs.getString(
Checkbox values rs.getString(
Checkbox values rs.getString(
Checkbox values rs.getString(
Checkbox values rs.getString(

/*OUTPUT*/


My question is why is it not printing out the value in rs.getString()???.

It would be great if this forum helps me in the right direction.Let me know how i can go about doing this.

I hope i have explained my question correctly.If you have any further questions kindly ask.

Thanking every one in adavance

AS
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

Chjeck the syntax of this line carefully



And, have you done a View Source from the browser? This is a basic debugging step that you should have taken long before posting here.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

And, if you are serious about

It would be great if this forum helps me in the right direction.


A first step in the right direction would be to not be dealing with result sets in the JSP page at all. Factor such processing out into a controller servlet. And check out the Model 2/MVC pattern for web applications.
nash avin
Ranch Hand

Joined: Nov 18, 2004
Posts: 45
Hi ,

Thanks for the replies.

I did change the syntax, to this...



ok....

But I get this error message.....



Kindly let me know what the problem could be..

Thanking you
AS
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Another useful tip is to print out your SQL statement to the browser.

You can then cut and paste it into whatever query tool your database offers. It's been a while since I've used Access but I recall that there was a tool that allows you to test queries.

It looks like your query is failing so your not getting a valid ResultSet.

If you want more help, post the code that is generating the resultset.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
nash avin
Ranch Hand

Joined: Nov 18, 2004
Posts: 45
Hi,

Thanks for the reply.This is my code for database access with MS access



Let me know if you require any further information from my side.

Help would be greatly appreciated.

Thanks
AS
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211


<INPUT TYPE=CHECKBOX NAME="COURSES" VALUE="<%out.print(rs.getString("course"));%>"><%out.print(rs.getString("course"));%>


Your problem could be calling rs.getString() twice on the same column.
Save the value received from rs.getString() in a variable, and then use it twice.
As Bear suggested, check out the MVC pattern, and try to keep your JDBC code out of JSPs, it will make debugging and maintenance much easier.

HTH.


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Nash,

I just noticed the code in your last post.
You are not closing the ResultSet before calling the getString() methods, are you?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410





Nash,

Where is this line in your code?
nash avin
Ranch Hand

Joined: Nov 18, 2004
Posts: 45
Hi,

Thanks a lot guys for your help.



This code is in a DataBaseBean.java



This code is in the courses.jsp file.

As was told to me, I am trying to put rs.getString("course") into a variable and call it twice.

Will see what happens.

Thanks a lot for your suggestions/ help.Let me know if you try and figure out what best can be done.

AS
nash avin
Ranch Hand

Joined: Nov 18, 2004
Posts: 45
Hello All,

Thanks for the friendly suggestion.I did manage to clear the error and I am on my way to tackle the next hurdle.

Declaring a variable and calling it 2 times did the trick.

Thanks again.

AS
 
 
subject: Kindly help me with this checkbox issue