connection string of jdbc odbc with MS access

六月ゝ 毕业季﹏ 提交于 2019-12-12 18:24:20

问题


I am trying to make jdbc odbc connection with ms access but not able to pass the password which is consisted from special characters

I am using the following code

 try
 {
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  Connection con=DriverManager.getConnection("Jdbc:Odbc:Driver={Microsoft Access   
  Driver(*.mdb); DBQ=d:/abc/xyz.mdb};","","password here");
   Statement st=con.createStatement();
 }
 catch(Exception ex)
 {

 }

but this is not recognising the password here even the password is much complex (combination of special characters)


回答1:


Following connection string for JDBC-ODBC is working correctly.

  try
   {

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String connectionQuery="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=path upto the database;uid=; pwd=password here;";  

    con = DriverManager.getConnection(connectionQuery,"",""); 
    st=con.createStatement();
    stmt=con.createStatement();

   }
    catch(Exception ex)
    {

     System.out.println("exception is"+ex);
    }



回答2:


Are you using 32-bit or 64-bit Windows? The URL string is different for each one:

http://www.selikoff.net/2011/07/26/connecting-to-ms-access-file-via-jdbc-in-64-bit-java/

Make your URL look just like the ones in this article or you'll have problems.

Empty catch blocks are always a bad idea. You won't know if an exception is thrown. How much work is it to print the stack trace?



来源:https://stackoverflow.com/questions/14278634/connection-string-of-jdbc-odbc-with-ms-access

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!