如何将UCanAccess连接到使用数据库密码加密的Access数据库? [英] How to connect UCanAccess to an Access database encrypted with a database password?
问题描述
我已经开发了一个带有Access数据库的Java应用程序(字典)来存储字典中的单词,并且我准备分发它. 我想用密码加密数据库,以防止人们访问我的文字. 当我设置密码时,Java代码显示此异常
I've developed a Java application (a dictionary) with an Access database to store the words of the dictionary and I'm getting ready to distribute it. I want to encrypt my database with a password to prevent people to access my words. When I set a passwords the Java code shows this Exception
net.ucanaccess.jdbc.UcanaccessSQLException: Decoding not supported. Please choose a CodecProvider which supports reading the current database encoding.
at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:247)
这是用密码加密数据库之前的连接代码.
Here is my connection code before encryption of my database with password ....
String s1="jdbc:ucanaccess://";
String user="";
String pass="";
String s4="words.accdb";
public void connectToDB(){
//database connection
try {
conn = DriverManager.getConnection(s1+s4,user,pass);
} catch (SQLException e) {
e.printStackTrace();
}
//end of database connection
}
这是用密码加密后的代码,例如12345 ...
Here is the code after the encryption with password for example 12345...
String s1="jdbc:ucanaccess://";
String user="";
String pass="12345";
String s4="words.accdb";
public void connectToDB(){
//database connection
try {
conn = DriverManager.getConnection(s1+s4,user,pass);
} catch (SQLException e) {
e.printStackTrace();
}
//end of database connection
}
推荐答案
如何将UCanAccess连接到使用数据库密码加密的Access数据库的步骤
Steps of How to connect UCanAccess to an Access database encrypted with a database password
步骤1:
将这两个软件包添加到您的项目中(jackcess-encrypt.jar,bcprov-ext-jdk15on-152)
Step 1:
Add these two packages to your project (jackcess-encrypt.jar, bcprov-ext-jdk15on-152)
您可以从以下链接下载这两个软件包:
You can download the two packages from the following links:
第2步:
您必须将此类添加到您的项目文件夹中
Step 2:
You have to add this class to your project folder
import java.io.File;
import java.io.IOException;
import net.ucanaccess.jdbc.JackcessOpenerInterface;
import com.healthmarketscience.jackcess.CryptCodecProvider;
import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.DatabaseBuilder;
public class CryptCodecOpener implements JackcessOpenerInterface {
@Override
public Database open(File fl,String pwd) throws IOException {
DatabaseBuilder dbd =new DatabaseBuilder(fl);
dbd.setAutoSync(false);
dbd.setCodecProvider(new CryptCodecProvider(pwd));
dbd.setReadOnly(false);
return dbd.open();
}
//Notice that the parameter setting autosync =true is recommended with UCanAccess for performance reasons.
//UCanAccess flushes the updates to disk at transaction end.
//For more details about autosync parameter (and related tradeoff), see the Jackcess documentation.
}
像这样
步骤3:
使用以下连接代码
step 3:
use the following connection code
public void connectToDB(){
try {
conn = DriverManager.getConnection("jdbc:ucanaccess://words.accdb;jackcessOpener=CryptCodecOpener", "user", "pass");
} catch (SQLException ex) {
ex.printStackTrace();
}
}
您也可以观看此视频... https://www.youtube.com/watch?v = TT6MgBBkRSE
You can also watch this video...https://www.youtube.com/watch?v=TT6MgBBkRSE
这篇关于如何将UCanAccess连接到使用数据库密码加密的Access数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!