• 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

Connecting to number of databases.

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have got five different databases i.e 5 different hosts.

I have to connect to them and retrieve data without making a performance hit.

My Code for establishing connection with single database is as follows.


Can any one help me out ???
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the question?
 
jagan raja
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to establish connection with 5 different host's at a time?
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do the above five times, with a different variable for each connection.
 
Ranch Hand
Posts: 466
1
IntelliJ IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can write a generic code and pass database details (which can be stored in some property of XML file) as parameter to establish connection....
 
jagan raja
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did that 5 times and it works fine.

But i want to know if there is any other simpler way of doing it.

Now my code is as below.


How to store these details in some property of XML file and use it?

Thanks in advance
 
Bartender
Posts: 2662
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(assuming this is a stand alone application)

You could create an XML file with contents like this:


And then, in your java code, use one of the XML APIs to read the file and create a connection for each occurrence of the <connection> tag.
You can store these connections in conArray.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you want several connections to the same database with the same login credentials? That is what you have. Or if the literal strings you posted were just examples, then you have a fixed number of connections.

I would have changed the makeConnection() method to pass the URL, username and password strings, and had the DriverManager.getConnection() method used the passed arguments. Or I would have wrapped all of this in a Connection wrapper class. Then each connection could use a different database and different credentials.
 
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic