java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
我应该怎么做..我需要帮助:/
这里是连接代码:
public gdUI(MainUI myParentFrame) {
this.myParentFrame = myParentFrame;
this.setSize(600, 500);
this.setVisible(true);
FillSeverity();
//DataBAse Connection
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=substituting_DB.accdb;";
conn = DriverManager.getConnection(database, "", "");
} catch (Exception e) {
e.printStackTrace();
}
initComponents();
}
答案 0 :(得分:1)
由于我发现需要在Windows下安装/配置数据源,因为MS-Access也不需要它,我建议使用另一个驱动程序ucanaccess:
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
String database = "jdbc:ucanaccess:////.../substituting_DB.accdb";
驱动程序需要额外的库;我的maven构建中有以下库依赖项:
<dependencies>
<dependency>
<groupId>com.healthmarketscience.jackcess</groupId>
<artifactId>jackcess</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>net.ucanaccess</groupId>
<artifactId>ucanaccess</artifactId>
<version>2.0.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>