aspose file tools*
The moose likes JSP and the fly likes Do you use a bean for creating database connection? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Do you use a bean for creating database connection?" Watch "Do you use a bean for creating database connection?" New topic
Author

Do you use a bean for creating database connection?

Raghavan Chockalingam
Ranch Hand

Joined: Dec 20, 2005
Posts: 77
I am wondering whether people develop a bean for making a database connection. I was thinking of creating of a bean that would return a Connection or Statement object and I came up with this java program but there is a problem when I try to include the bean in my jsp program.

java program...DbBean.java...placed in web-inf/classes/Utilities


Jsp file...carBean.jsp



Errors....taken from log file..

[ January 03, 2006: Message edited by: Raghavan Chockalingam ]

Raghavan
SCJP 6
Balasubramani Dharmalingam
Ranch Hand

Joined: Dec 06, 2004
Posts: 116
Raghav,
you have used default access to DbBean class so it is not visible to the JSP. so change access specifier for DbBean class as public.


Balasubramani SD,<br />SCJP 1.4,SCWCD 1.4,SCJP 5.0<br /><a href="http://sd.balasubramani.googlepages.com" target="_blank" rel="nofollow">www.sd.balasubramani.googlepages.com</a>
Raghavan Chockalingam
Ranch Hand

Joined: Dec 20, 2005
Posts: 77
Sorry about that...now I have changed it to public and compiled again but I have the same error even then...

I want to know the .java file is a valid bean???


[ January 03, 2006: Message edited by: Raghavan Chockalingam ]
Balasubramani Dharmalingam
Ranch Hand

Joined: Dec 06, 2004
Posts: 116
Raghav,
I tried the samething here. I am also getting same error.But after changing the access as public the error has gone.
did u restart the server after compiling the DbBean class ?
Amarender Reddy
Ranch Hand

Joined: May 12, 2005
Posts: 54
Raghavan,
Can you make sure that the given error is thrown excatly the line :



cheers
Raghavan Chockalingam
Ranch Hand

Joined: Dec 20, 2005
Posts: 77
Thanks both of you guys for your help and I did not know earlier that I should restart the server.

1. Is it always necessary to restart the server whenever there is a revision with the bean class?

2. I now have a logical problem, if the bean creates a Connection or a Statement object then how do I use those objects in the .jsp file???

For example....
<jsp:getProperty name="myConnection" property="stmt" />

the above statement gives a Statement object but how do I assign this object to a Statement object created in jsp scriptlet.



If you think I am totally wrong with the way I am thinking, can you tell me how do you establish/ use database connections in your applications. It would be very kind if you can me a working example of yours...thank you...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42908
    
  68
to 1) It is not necessary to restart the server if a class changes, but it is necessary to restart the web app that contains that class.

to 2) It is considered bad design to be using java.sql objects in a JSP page (and has practical drawbacks as well, like making exception handling hard). At a minimum, perform all the DB access in the bean class, and just retrieve the results from it in the JSP.
Raghavan Chockalingam
Ranch Hand

Joined: Dec 20, 2005
Posts: 77
Thanks Ulf for your advice, can you tell me how to restart the Web application alone???
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Raghavan Chockalingam:
Thanks Ulf for your advice, can you tell me how to restart the Web application alone???


The Manager app that ships with Tomcat can be used for restarting applications.
http://tomcat.apache.org/tomcat-5.5-doc/manager-howto.html


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Do you use a bean for creating database connection?