lightdb-jdbc 是恒生 lightdb 分布式数据库驱动,针对开源的 postgresql 驱动进行了优化,使用上 100% 兼容原生的 pg 驱动。
lightdb 官网 https://www.hs.net/lightdb
使用限制
需要 java8 及以上。
引入依赖
io.github.hslightdb
lightdb-jdbc
42.2.24
最新版本可以通过 https://mvnrepository.com/ 搜索获取
使用 lightdb-jdbc *** 作数据库
public void jdbcDemo() {
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
Class.forName("org.postgresql.Driver"); // 加载驱动
connection = DriverManager.getConnection("${jbdcUrl}", "${username}", "${password}");
preparedStatement = connection.prepareStatement("SELECT * FROM mytable WHERE columnfoo = 500");
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
System.out.print("Column 1 returned ");
System.out.println(resultSet.getString(1));
}
} catch (Exception e) {
/* handle exception */
} finally {
safeClose(resultSet);
safeClose(preparedStatement);
safeClose(connection);
}
}
public void safeClose(AutoCloseable closeable) {
try {
closeable.close();
} catch (Exception e) {
/* handle exception */
}
}
与 mybatis 集成
只需要将原生的 postgresql 驱动替换为 lightdb-jdbc 驱动即可使用。
驱动参数
100% 兼容原生 postgresql 驱动,驱动参数可以参考以下链接。
https://jdbc.postgresql.org/documentation/head/connect.html#connection-parameters
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)