0
連接DB2數據庫,我不能對DB2數據庫在Springsoruce連接,並提示以下錯誤:,錯誤在Java中
2017/05/19 10:10:31.588 [ERROR] An unexpected error occurred when attempting to establish connection to database. The error was: com.ibm.db2.jcc.c.fc.a(fc.java:371) 371
com.ibm.db2.jcc.c.fc.<init>(fc.java:66) 66
com.ibm.db2.jcc.c.a.v(a.java:255) 255
com.ibm.db2.jcc.c.b.a(b.java:1796) 1796
com.ibm.db2.jcc.b.p.<init>(p.java:934) 934
com.ibm.db2.jcc.c.b.<init>(b.java:324) 324
com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:165) 165
java.sql.DriverManager.getConnection(DriverManager.java:579) 579
java.sql.DriverManager.getConnection(DriverManager.java:221) 221
com.waitrose.of.DBConnection.getDBConnection(DBConnection.java:19) 19
com.waitrose.of.Controller.business_logic(Controller.java:28) 28
com.waitrose.of.Main.main(Main.java:21) 21
以下外部JAR的都包括在該計劃,但仍然得到了錯誤,而建立連接到數據庫。
db2jcc.jar
db2jcc_license_cisuz.jar
db2java.jar
下面是我使用建立數據庫連接和數據庫的細節是從命名設置另一個類文件中導出的代碼,
import java.io.BufferedReader;
import java.sql.Connection;
import java.sql.DriverManager;
public class DBConnection
{
logWriter LogWriter = new logWriter();
public Connection getDBConnection = null;
public Connection getDBConnection() {
Connection DBConnection = null;
try {
System.out.println("Connecting to OF database " + Settings.DBName + ".");
String DBURL = "jdbc:db2://" + Settings.DBServer + ":" + Settings.DBPort + "/" + Settings.DBName + ":currentSchema=" + Settings.DBSchema + ";";
System.out.println(DBURL);
DBConnection = DriverManager.getConnection(DBURL, "username", "password");
LogWriter.writeEvent(3, "Database connection successfully established to database " + Settings.DBName + " using user " + Settings.DBUser + ".");
return DBConnection;
}
catch (Exception e)
{
LogWriter.writeEvent(1,"An unexpected error occurred when attempting to establish connection to database " + Settings.DBName + ". The error was: " + LogWriter.getStackTraceString(e)+ "\r\n");
}
return DBConnection;
}
}
樣品URL模板:
的jdbc:DB2: //主機名:端口號/數據庫
嗨,我已經添加了代碼部分。你可以看看它嗎? –