File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Get Database connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Get Database connection" Watch "Get Database connection" New topic

Get Database connection

Dan Parsons
Ranch Hand

Joined: May 30, 2007
Posts: 70
I have the below data class that connects to Oracle without any issues in Tomcat 6.0.18. The web app is used about once or twice a week by 5 users.
Everytime I connect in a class I have to use the same setter and getter methods so I would like to put them in a seperate bean class and call it in each java class.
Here is what I have that currently works:

I tried putting it in a ConnBean java class like this:

New connection attempt keeps saying it cant find any connection info:

Please advise how I can make this work?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2904

TellTheDetails and I saw there is no constructor in ConnBean which takes the Connection as an input parameter

[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Jan Cumps

Joined: Dec 20, 2006
Posts: 2565

...and I saw there is no constructor in ConnBean which takes the Connection as an input parameter...

Indeed. The code given by Dan does not compile.

Dan, please post the real code, and the real error messages.

Regards, Jan

OCUP UML fundamental and ITIL foundation
Gavi jadz Grandea

Joined: Sep 11, 2009
Posts: 17
I think what your trying to do is...

to get the connection.
Somnath Mallick
Ranch Hand

Joined: Mar 04, 2009
Posts: 482
You can also get rid of the constructor and make the variables and methods static! Shift the getConnection() to the class City as a private method. So then you can just call them like:

I agree. Here's the link:
subject: Get Database connection
It's not a secret anymore!