Hello,

Can anybody help me for connection to multiple database dynamically.
Its means I wann to connect the respective database by choosing of the user , Tell take an exmple we have 3 clients namely C1,C2,C3 and having respective databases namely D1,D2,D3.

I want to connect the database D1 if the C1 user click ......

I try to change at :

Class.forName("org.gjt.mm.mysql.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/D1,"root","root");

If anybody help me , can i take a variable dbname at D1 then it can be easy dynamically,
if i save the database name in 'dbname' and use it at the connection path it will be easy.


Thanks
Ashish

Expecting that user record is in some way associated with database name only thing you need to do is build connection string that can be done simply as

public String buildConnectionString(String dbName){
    return new StringBuilder("jdbc:mysql://localhost:3306/").append(dbName).toString();
}

Thanks peter its nice ....its work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.