netbeans无法连接到数据库accdb

时间:2012-12-19 12:32:42

标签: database ms-access netbeans

我正在使用netbeans并且我无法在我的comptuer编译代码,它适用于我的朋友计算机

我正在使用microsoft access 2007 for database 即时通讯使用Windows 7 64位 所以这是错误 它是驱动程序错误还是什么?

  

run:Dec 19,2012 7:26:55 PM DBConnect SEVERE:null   java.sql.SQLException:[Microsoft] [ODBC驱动程序管理器]数据源   找不到名称,并且未指定默认驱动程序   sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6956)at at   sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7113)at at   sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3072)at at   sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)     在sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)at at   java.sql.DriverManager.getConnection(DriverManager.java:579)at   java.sql.DriverManager.getConnection(DriverManager.java:243)at   DBConnect。(DBConnect.java:18)at   LoginForm。(LoginForm.java:31)at   MainForm。(MainForm.java:23)at   MainForm $ 10.run(MainForm.java:265)at   java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)at   java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)at at   java.awt.EventQueue.access $ 200(EventQueue.java:103)at   java.awt.EventQueue $ 3.run(EventQueue.java:682)at   java.awt.EventQueue $ 3.run(EventQueue.java:680)at   java.security.AccessController.doPrivileged(Native Method)at   java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:76)     在java.awt.EventQueue.dispatchEvent(EventQueue.java:691)at   java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)     在   java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)     在   java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)     在   java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)     在   java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)     at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)

     

2012年12月19日下午7:26:55 DBConnect SEVERE:null   java.sql.SQLException:[Microsoft] [ODBC驱动程序管理器]数据源   找不到名称,并且未指定默认驱动程序   sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6956)at at   sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7113)at at   sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3072)at at   sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)     在sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)at at   java.sql.DriverManager.getConnection(DriverManager.java:579)at   java.sql.DriverManager.getConnection(DriverManager.java:243)at   DBConnect。(DBConnect.java:18)at   MasterEmployee。(MasterEmployee.java:33)at   MainForm。(MainForm.java:24)at   MainForm $ 10.run(MainForm.java:265)at   java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)at   java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)at at   java.awt.EventQueue.access $ 200(EventQueue.java:103)at   java.awt.EventQueue $ 3.run(EventQueue.java:682)at   java.awt.EventQueue $ 3.run(EventQueue.java:680)at   java.security.AccessController.doPrivileged(Native Method)at   java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:76)     在java.awt.EventQueue.dispatchEvent(EventQueue.java:691)at   java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)     在   java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)     在   java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)     在   java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)     在   java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)     at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)

     

线程中的异常" AWT-EventQueue-0"显示java.lang.NullPointerException     在DBConnect.query(DBConnect.java:28)at   MasterEmployee。(MasterEmployee.java:35)at   MainForm。(MainForm.java:24)at   MainForm $ 10.run(MainForm.java:265)at   java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)at   java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)at at   java.awt.EventQueue.access $ 200(EventQueue.java:103)at   java.awt.EventQueue $ 3.run(EventQueue.java:682)at   java.awt.EventQueue $ 3.run(EventQueue.java:680)at   java.security.AccessController.doPrivileged(Native Method)at   java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:76)     在java.awt.EventQueue.dispatchEvent(EventQueue.java:691)at   java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)     在   java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)     在   java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)     在   java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)     在   java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)     at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)   建立成功(总时间:2秒)

1 个答案:

答案 0 :(得分:0)

前一段时间我遇到了同样的问题,包括.accdb数据库。看起来Java 6支持.mdb格式,但是.accdb文件格式不太好,或者至少需要在Windows上安装MS-Access数据连接组件才能工作。

这可能是导致它无法在您的计算机上编译并在朋友计算机上编译的原因。

无论如何,我在MSDN上找到了它,但它有效。

class MyConnection 
{
  public static Connection getConnection() throws Exception 
  {
   Driver d = (Driver)Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
   Connection c = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver   (*.mdb, *.accdb)};DBQ=*.accdb");
return c;
}

您需要从Microsoft网站下载并安装“MS-Access数据连接组件”才能使用。