• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Kindly help me with this checkbox issue

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
nash avin
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


<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.
 
Sonny Gill
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




Nash,

Where is this line in your code?
 
nash avin
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bring me the box labeled "thinking cap" ... and then read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic