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

Do you use a bean for creating database connection?

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Raghavan Chockalingam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Raghavan,
Can you make sure that the given error is thrown excatly the line :



cheers
 
Raghavan Chockalingam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ulf for your advice, can you tell me how to restart the Web application alone???
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Do not meddle in the affairs of dragons - for you are crunchy and good with ketchup. Crunchy tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic