我有 Connection 类的代码,它只从一个数据库获取连接。看看下面的 DBConnection.java
package eksim.db.sql;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBConnection {
public Connection conn=null;
private static DBConnection dbConn=null;
static final String DB_URL=
"jdbc:sqlserver://10.0.0.47\\test;databaseName=a;";
static final String DB_USER="sa";
static final String DB_PASS="123";
public DBConnection(){
if(conn==null){
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
conn=DriverManager.getConnection(DB_URL, DB_USER, DB_PASS);
}
catch(Exception ex){
ex.printStackTrace();
}
}
}
public static DBConnection getInstance(){
DBConnection conn=null;
if(dbConn==null){
System.out.println("New");
dbConn=new DBConnection();
conn=dbConn;
} else{
conn=dbConn;
}
return conn;
}
public Connection getCon() throws SQLException{
return this.conn;
}
}
现在,我想创建另一个到不同数据库的连接。任何人都可以给我建议修改此代码以便将 Connection 的结果放入 2 个数据库中吗?感谢您的回复