I just joined in a small company they are using some java code in jsp but i don't like to use java code in jsp. So, i ask permission to my M.D to develop an application M.V.C architecture Using only Servlets,java beans and JSP (No frame work) i am facing some problems like each time opening connection in servlet to connect the database and "setting primary key available to entire/part of some pages" in my application.
Please help me to develop the application and suggest some books and sites need to develop M.V.C pattern Thanks
There are several books and articles on he MVC pattern on the internet. I am not exactly clear on your question though, but it sounds like you are opening a connection to the database on each request, and you are concerned right?
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
I didn't say anything about opening a connection in the JSP. You said:
, in some jsp it's throwing some exception like statement is closed
Why would your JSPs care about a connection? Database access should be over and done with before any JSP is forwarded to. Do you have Java code in your JSPs accessing a result set?
In fact, if you are doing any database access even at the servlet level, you are violating the precepts of MVC. All database access and information should be handled by the Model -- not the Controller or the View.
mallikarjun don wrote:Then how to return result-set?
You never want to return a result set. Results sets should be closed and the statements and connections reclaimed as soon as possible. What data do you need from your DAO? It looks like all you want is a boolean indicating if the record exists or not, but that's not what your code is doing (and your SQL is highly inefficient for that).
Bear Bibeault wrote:
If you only care whether the record exists or not, why fetch all the data with a "select *"? To check for existence a "select count(*)" will be more efficient.
Hi Bear. I'm wondering if select count(*) would really be more efficient than say select username. I'm thinking that for select count(*) it has to read every row in the table no matter what, whereas for select username it will stop searching when the row is found.