在 Java 独立客户端服务器应用程序(使用 Netbeans)中,我使用静态方法连接到 SQL 服务器:但是如果我使用第二个连接,我会收到错误:
Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: Utili.StaticConnessione.getConnessione2()Ljava/sql/Connection;
有人可以帮助我吗? 谢谢
public class StaticConnessione {
// first coonection
public static Connection getConnessione1() throws SQLException {
String s = System.getProperty("user.name");
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
return DriverManager.getConnection("jdbc:jtds:sqlserver://localhost;databaseName=FIRST_DB;user=sa; password = abc");
} catch (ClassNotFoundException e) {
JOptionPane.showMessageDialog(null, e.toString(), "msg", 2);
}
return null;
}
// second connection
public static Connection getConnessione2() throws SQLException {
// first coonection
String s = System.getProperty("user.name");
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
return DriverManager.getConnection("jdbc:jtds:sqlserver://localhost;databaseName=SECOND_DB;user=sa;password = abc");
} catch (ClassNotFoundException e) {
JOptionPane.showMessageDialog(null, e.toString(), "msg", 2);
}
return null;
}
最佳答案
您可以在调用 getConnessione1 和 getConnessione2 的地方发布代码吗?此外,您可能应该考虑使用连接池来访问您的数据库。
关于java - 使用jdbc查询两个数据库到同一个sql server实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15729979/