The moose likes Struts and the fly likes Dynamic Database Connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Reply locked New topic

Dynamic Database Connection

Jagadish Jain

Joined: Apr 05, 2012
Posts: 8

Im developing a project where in the connection to DataBase is static i.e Im hard coding the details of the database in createConnection() method.
Now Im required to dynamically connect to a database i.e in the first page of my project, the user enters the database details(servername,port,username,passowrd,servicename) and using this details my project should be connected to respective database.

One solution to this is to have my createConnection() method as createConnection(String serverName,String portNumber,
String userName,String pword,String s_id).
But my project is very vast and everywhere I have used createConnection() to connect to database, changing this method to createConnection(String serverName,String portNumber,
String userName,String pword,String s_id) everywhere is not possible.
So im looking for an alternative solution.
Thanks in Advance :-)
Matthew Brown

Joined: Apr 06, 2010
Posts: 4542

Hi. Welcome to The Ranch. But can you avoid posting the same message to more than one thread, please? Thanks.

Duplicate of
I agree. Here's the link:
subject: Dynamic Database Connection
It's not a secret anymore!