非凡巅峰
2018-01-23 07:28
采纳率: 66.7%
浏览 2.1k
已采纳

java读取有密码的mdb文件总是报错说密码无效,求帮助!

java.sql.SQLException: [Microsoft][ODBC Microsoft Access 驱动程序] 密码无效。
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6964)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7121)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3080)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:187)
at com.diit.web.onemap.test.test.readFileACCESS(test.java:115)
at com.diit.web.onemap.test.test.TestSaveMethod(test.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
[]

以下是测试代码,当我使用一个没有密码的mdb文件进行测试的时候不会存在任何问题,但是当有密码的时候就会报错无效密码,搞不懂为什么

public static List readFileACCESS(String filePath) {

List maplist= new ArrayList();

Properties prop = new Properties();

prop.put("charSet", "gb2312"); //这里是解决中文乱码

prop.put("user", "");

// prop.put("PASSWORD", "");
prop.put("PASSWORD", "GTZYBDZZK2012");
String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="+filePath; //文件地址

PreparedStatement ps=null;

Statement stmt=null;

ResultSet rs=null;

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection conn=DriverManager.getConnection(url,prop);

stmt = (Statement)conn.createStatement();

           rs=stmt.executeQuery("select * from 02XiangMu");  
           ResultSetMetaData data=rs.getMetaData();  

         while(rs.next()) {  
         Map map= new HashMap();  
          for(int i = 1 ; i<= data.getColumnCount() ; i++){   
           String columnName =data.getColumnName(i);    //列名  
           String  columnValue= rs.getString(i);   
            map.put(columnName, columnValue);  
          }  
            maplist.add(map);     
         }  
      } catch (Exception e) {  
       // TODO Auto-generated catch block  
       e.printStackTrace();  
      }  
       return maplist;   
     }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • 键盘哥 2018-01-23 07:30
    已采纳

    1,如果是64位系统一定要按装64的ODBC驱动,未安装64位ODBC驱动的话在ODBC配置程序中的平台一列显示32位,安装之前的32位驱动要删除
    64位驱动下载地址
    https://www.microsoft.com/zh-cn/download/details.aspx?id=13255

    https://download.microsoft.com/download/E/4/2/E4220252-5FAE-4F0A-B1B9-0B48B5FBCCF9/AccessDatabaseEngine_X64.exe
    2,url的写法必须要跟ODBC的配置程序中的写法一致,比如:
    jdbc:odbc:driver={Microsoft Access Driver (.mdb, .accdb)};DBQ=g:\aaa1.mdb
    其中Driver 后面有空格,*.accdb前面有空格
    3,access文件路径必须正确
    4,如果还是不行在系统DSN中也添加一个64位数据源试试

    点赞 评论
  • cc247017 2018-01-23 12:17

    下一个64位的库

    点赞 评论

相关推荐 更多相似问题