SQLite Security ODBC/JDBC 驱动实现了Linux、Windows、Android 等平台下通过标准接口访问SQLite数据库的能力, 对于熟悉JDBC/ODBC的开发人员很容易上手,同时也便于现有的项目由其他数据库向SQLite数据库的移植。
ODBC 加密驱动的一个列子
// 只是在数据库连接上有一点区别,其他接口调用相同
SQLDriverConnect(dbc, NULL, (SQLCHAR *) "Driver={SQLite3 ODBC Driver(SEE)};Database=test.db;PWD=加密密钥",
SQL_NTS, NULL, 0, NULL, SQL_DRIVER_COMPLETE | SQL_DRIVER_NOPROMPT);
JDBC 加密驱动的一个列子
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
public class JDBCTest1 {
static final String LOG_TAG = "JDBCTest1";
private Connection conn;
private Statement stat;
private String dbpath;
public JDBCTest1(String dbpath) {
this.dbpath = dbpath;
}
private void connect(String dbfile) throws Exception {
new File(dbfile).delete();
Properties info = new Properties();
/* 加密 密码 */
byte[] key = new byte[] { 'a', 'b', 'c', 'd', 'e', '8', 0 };
info.put("key", key);
Class.forName("org.sqlite.JDBC");
conn = DriverManager.getConnection("jdbc:sqlite:" + dbfile, info);
stat = conn.createStatement();
}
private void close() throws SQLException {
stat.close();
conn.close();
}
private void testUpdate() throws SQLException {
conn.prepareStatement("create table s1 (c1);").executeUpdate();
PreparedStatement prep = conn
.prepareStatement("insert into s1 values (?);");
prep.setInt(1, 3);
prep.executeUpdate();
prep.setInt(1, 5);
prep.executeUpdate();
prep.setInt(1, 7);
prep.executeUpdate();
prep.close();
ResultSet rs = stat.executeQuery("select sum(c1) from s1;");
rs.next();
System.out.println(LOG_TAG + ": testUpdate result = " + rs.getInt(1));
rs.close();
}
public void runTest() throws Exception {
String dbfile = dbpath + "jdbctest1.db";
connect(dbfile);
testUpdate();
close();
}
public static void main(String[] args) {
JDBCTest1 test = new JDBCTest1("d:\\");
try {
test.runTest();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
JDBC、ODBC 加密驱动下载及更详细的技术文档,可以到百度网盘下载:
https://pan.baidu.com/s/1KUWqwNMRP-A9DJ6RiKlxWQ