java 带有 MS 访问权限的 jdbc odbc 的连接字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14278634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
connection string of jdbc odbc with MS access
提问by adesh singh
I am trying to make jdbc odbc connection with ms access but not able to pass the password which is consisted from special characters
我正在尝试使用 ms access 建立 jdbc odbc 连接,但无法传递由特殊字符组成的密码
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)
但这并不能识别这里的密码,即使密码非常复杂(特殊字符的组合)
回答by adesh singh
Following connection string for JDBC-ODBC is working correctly.
以下 JDBC-ODBC 连接字符串工作正常。
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);
}
回答by duffymo
Are you using 32-bit or 64-bit Windows? The URL string is different for each one:
您使用的是 32 位还是 64 位 Windows?每个 URL 字符串都不同:
http://www.selikoff.net/2011/07/26/connecting-to-ms-access-file-via-jdbc-in-64-bit-java/
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.
使您的 URL 看起来像本文中的 URL,否则您会遇到问题。
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?
空的 catch 块总是一个坏主意。你不会知道是否抛出异常。打印堆栈跟踪需要多少工作?