| Author |
need some help in MVC
|
mallikarjun dontamsetti
Ranch Hand
Joined: Mar 18, 2011
Posts: 231
|
|
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
|
 |
dileep keely
Ranch Hand
Joined: Jun 28, 2010
Posts: 91
|
|
|
Can you let us know what is the problem?
|
 |
Bosun Bello
Ranch Hand
Joined: Nov 06, 2000
Posts: 1506
|
|
|
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
|
 |
mallikarjun dontamsetti
Ranch Hand
Joined: Mar 18, 2011
Posts: 231
|
|
|
My problem is opening Connection in every Sevlet for each table and when i them close at end of servlet, in some jsp it's throwing some exception like statement is closed
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56168
|
|
Why do you need a connection in the JSP? The JSP shouldn't be doing any database access at all. If it is, your code is not following best practices.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
mallikarjun dontamsetti
Ranch Hand
Joined: Mar 18, 2011
Posts: 231
|
|
|
I am not opening connection in jsp. I am opening connection in servlet and when i close the connection it is throwing exception like statement is closed
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56168
|
|
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 dontamsetti
Ranch Hand
Joined: Mar 18, 2011
Posts: 231
|
|
model means i am using a java class like
//connecting to database
//connecting servlet
But it is always going to else statement even i enter the correct values in html page. wat is wrong
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56168
|
|
|
Does your DAO compile like that? How can you return a result set as a boolean? Where do you close the connection? Why aren't you using a connection pool?
|
 |
mallikarjun dontamsetti
Ranch Hand
Joined: Mar 18, 2011
Posts: 231
|
|
|
Then how to return result-set? I don't have any idea about connection pooling
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56168
|
|
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).
I don't have any idea about connection pooling
Time to learn: connection pooling.
|
 |
mallikarjun dontamsetti
Ranch Hand
Joined: Mar 18, 2011
Posts: 231
|
|
and your SQL is highly inefficient for that.
What is this means i can not understand please tell me
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56168
|
|
|
At this point this has become much more about JDBC than Servlets, so this topic has been moved to the JDBC forum.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56168
|
|
mallikarjun don wrote:
and your SQL is highly inefficient for that.
What is this means i can not understand please tell me
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.
|
 |
mallikarjun dontamsetti
Ranch Hand
Joined: Mar 18, 2011
Posts: 231
|
|
|
rs.next() What it returns if value is correct?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56168
|
|
|
Easy enough to check... give it a try.
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26168
|
|
mallikarjun don wrote:rs.next() What it returns if value is correct?
When you use count(*), there is no such thing as correct/not correct. rs.next() will always return true and then rs.getInt(1) gives you the number of records the count found. Possibly zero.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Rudy Gireyev
Ranch Hand
Joined: May 03, 2011
Posts: 39
|
|
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.
|
 |
 |
|
|
subject: need some help in MVC
|
|
|