switch connection

In my class, I have static value Connection,

public static Connection con;

public static Connection getConnection(...) {

con = (Connection) DriverManager.getConnection(url, dbUser, dbPass);

return con;

}

Now I want to switch to another connection in an aother function, so I tried:

public static Connection switchConnection (...) {

con.close();

con = (Connection) DriverManager.getConnection(newUrl, newDbUser, newDbPass);

return con;

}

Is OK with this way.

Thanks

[553 byte] By [suhua] at [2007-11-27 5:36:07]
# 1
Just make sure that your existing connection is not in use before you swap. I can't think of a way to enforce this programatically, so you'll just have to be bloody careful.Apart from that I can't see a problem... it works doesn't it?
corlettka at 2007-7-12 15:06:13 > top of Java-index,Java Essentials,Java Programming...
# 2
ThanksYou right, i should be careful about existing connection - is not in usedRegardsshu
suhua at 2007-7-12 15:06:13 > top of Java-index,Java Essentials,Java Programming...