This week's book giveaway is in the Open Source forum.
We're giving away four copies of Programmers Guide to Apache Thrift and have Randy Abernethy on-line!
See this thread for details.
Win a copy of Programmers Guide to Apache Thrift this week in the Open Source forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Using same database connection  RSS feed

 
Ranch Hand
Posts: 66
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have a main Jframe and then some jdialog depends of the jframe.
In one jdialog I set up a database connection that after I would like to use in lifecycle of application.
How is the best way to make that? With object connection public? Could you suggest me how could I do that?
Thanks and sorry for my English
 
Saloon Keeper
Posts: 10206
216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it kinda depends on what kind of information you require the user to enter in the dialog. One way to do it is have the dialog return a DataSource, which you can then pass from your frame to the persistence layer.
 
Bartender
Posts: 20721
124
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like what you probably need is a singleton object that you can obtain the Connection from (have it create the Connection the first time it is called).

For multi-user applications (Swing apps usually aren't), there are some Database Connection Pool libraries such as Apache dbcp that can be used to manage shared pools with multiple connections in them. Apps like Apache Tomcat use* this instead of inventing their own).

===
* Actually, up to about Tomcat 7, they used Apache dbcp, I think later versions switched to a different provider. Tomcat's connection pooler was always plug-replaceable though.
 
david luis
Ranch Hand
Posts: 66
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:I guess it kinda depends on what kind of information you require the user to enter in the dialog. One way to do it is have the dialog return a DataSource, which you can then pass from your frame to the persistence layer.





These is my organizacion:

JFRAME (main) -> multiple buttons that open JDIALOGs to make querys in database and one of them open Jdialog to configure database (for instance JDialogDatabase)
JDIALOG JDialogDatabase with JTextField with name database, user, port, pass...., and Jbutton to text connectivity of that configuration
CLASS CONNECTION -> Is called from JDIALOG JDialogDatabase to connect to database and return to JDIALOG the output of the connection to see the connection is established.

How could you organize better that?

Thanks!


 
david luis
Ranch Hand
Posts: 66
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:It sounds like what you probably need is a singleton object that you can obtain the Connection from (have it create the Connection the first time it is called).

For multi-user applications (Swing apps usually aren't), there are some Database Connection Pool libraries such as Apache dbcp that can be used to manage shared pools with multiple connections in them. Apps like Apache Tomcat use* this instead of inventing their own).

===
* Actually, up to about Tomcat 7, they used Apache dbcp, I think later versions switched to a different provider. Tomcat's connection pooler was always plug-replaceable though.




I don't want multi-user configuration. These is my organizacion:

JFRAME (main) -> multiple buttons that open JDIALOGs to make querys in database and one of them open Jdialog to configure database (for instance JDialogDatabase)
JDIALOG JDialogDatabase with JTextField with name database, user, port, pass...., and Jbutton to text connectivity of that configuration
CLASS CONNECTION -> Is called from JDIALOG JDialogDatabase to connect to database and return to JDIALOG the output of the connection to see the connection is established.

How could you organize better that?

Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!