• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Retrieving contents of more than one table in jsp

 
Ranch Hand
Posts: 75
Eclipse IDE AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two tables in my database named "branch" and "course". I want to display contents of one column of each table in a select option. I can retrieve one column successfully but when i try to retrieve data from more than one table it gives me an Exception which says "result set is closed".

Here's my code:-

 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which result set is closed: "r" or "r1"? One way to avoid this is to just use one result set variable. Populate 1 select list at a time and reuse the same result set variable.

By the way, you really should do the query in a servlet.
 
Sheriff
Posts: 67746
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
You should not be doing Java code in a JSP.

In any case, this is a JDBC question and has been moved appropriately.
 
Saumyaraj Zala
Ranch Hand
Posts: 75
Eclipse IDE AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

By the way, you really should do the query in a servlet.


But the java code here helps in making my jsp page. I use the servlets to do computations and according to the result just transfer the control of a web page. How can i implement this as a servlet? Am i going wrong?
 
Saumyaraj Zala
Ranch Hand
Posts: 75
Eclipse IDE AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

K. Tsang wrote:Which result set is closed: "r" or "r1"? One way to avoid this is to just use one result set variable. Populate 1 select list at a time and reuse the same result set variable.



After the making my first select tag i am closing the first result set and after making second i am closing the second result set.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what happens when you 100% mix server code with client code.

jsp pages are ONLY for displaying data. you are not supposed to make database request directly in them. Just because you can, does not mean you should.

- What you should do is to make a Servlet Filter that gets called before the jsp is loaded.
- In Servlet Filter - make a call to a Servlet Controller (or do it directly in the filter if you are lazy) to get the data you want to display on the jsp.
- In Servlet Controller - make a call to the Data Access Object classes needed
- In Data Access Object class - get a connection from Database class, then get the data, close connection and return it
- when the data has been returned back to the Servlet Filter, can you make a session or just pass the data in the request to the jsp.
- In JSP - read data from session or request and display it.

I know this might seam like overkill, but it is just good practice to seperate the different parts to the place they belong.
reply
    Bookmark Topic Watch Topic
  • New Topic