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".
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.
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?
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.
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.