diff --git a/README.md b/README.md index eac8ef2..37963c7 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,30 @@ Token based authentication supported in version 1.0. Pass token value as passwor Driver class name: `com.dbeaver.jdbc.driver.libsql.LibSqlDriver` +## Example + +```java +import java.sql.*; + +public class LibSqlTest { + public static void main(String[] args) throws Exception { + String databaseUrl = "http://libsql-server.company.local:8080"; + try (Connection connection = DriverManager.getConnection("jdbc:dbeaver:libsql:" + databaseUrl)) { + try (Statement statement = connection.createStatement()) { + statement.execute("drop table if exists test_table_1"); + statement.execute("create table test_table_1 (id integer, name string)"); + statement.execute("insert into test_table_1 values(1, 'test one')"); + statement.execute("insert into test_table_1 values(2, 'test two')"); + try (ResultSet rs = statement.executeQuery("select * from test_table_1")) { + while (rs.next()) { + System.out.println(rs.getInt("id") + " = " + rs.getString("name")); + } + } + } + } + } +} +``` ## License Licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) diff --git a/com.dbeaver.jdbc.driver.libsql/META-INF/MANIFEST.MF b/com.dbeaver.jdbc.driver.libsql/META-INF/MANIFEST.MF index c8e068e..a0c152e 100644 --- a/com.dbeaver.jdbc.driver.libsql/META-INF/MANIFEST.MF +++ b/com.dbeaver.jdbc.driver.libsql/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: DBeaver LibSQL JDBC Driver Bundle-SymbolicName: com.dbeaver.jdbc.driver.libsql -Bundle-Version: 1.0.2.qualifier +Bundle-Version: 1.0.3.qualifier Bundle-Release-Date: 20230522 Bundle-RequiredExecutionEnvironment: JavaSE-17 Export-Package: com.dbeaver.jdbc.driver.libsql, diff --git a/com.dbeaver.jdbc.driver.libsql/pom.xml b/com.dbeaver.jdbc.driver.libsql/pom.xml index 4f6f82a..2b6c334 100644 --- a/com.dbeaver.jdbc.driver.libsql/pom.xml +++ b/com.dbeaver.jdbc.driver.libsql/pom.xml @@ -7,7 +7,7 @@ com.dbeaver.jdbc jdbc-libsql - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT ../pom.xml com.dbeaver.jdbc.driver.libsql diff --git a/com.dbeaver.jdbc.driver.libsql/src/main/java/com/dbeaver/jdbc/driver/libsql/LibSqlConnection.java b/com.dbeaver.jdbc.driver.libsql/src/main/java/com/dbeaver/jdbc/driver/libsql/LibSqlConnection.java index 2e7f8ff..85b913e 100644 --- a/com.dbeaver.jdbc.driver.libsql/src/main/java/com/dbeaver/jdbc/driver/libsql/LibSqlConnection.java +++ b/com.dbeaver.jdbc.driver.libsql/src/main/java/com/dbeaver/jdbc/driver/libsql/LibSqlConnection.java @@ -51,13 +51,18 @@ public LibSqlConnection( this.driverProperties = driverProperties; try { - String token = CommonUtils.toString(driverProperties.get("password")); + String token = CommonUtils.toString(driverProperties.get("password"), null); this.client = new LibSqlClient(new URL(url), token); } catch (IOException e) { throw new SQLException(e); } - // Verify connection - LibSqlUtils.executeQuery(this, "SELECT 1"); + try { + // Verify connection + LibSqlUtils.executeQuery(this, "SELECT 1"); + } catch (Exception e) { + close(); + throw e; + } } public LibSqlClient getClient() { diff --git a/com.dbeaver.jdbc.driver.libsql/src/test/java/com/dbeaver/jdbc/upd/driver/test/LibSqlDriverTest.java b/com.dbeaver.jdbc.driver.libsql/src/test/java/com/dbeaver/jdbc/upd/driver/test/LibSqlDriverTest.java index 763b8ee..1f16354 100644 --- a/com.dbeaver.jdbc.driver.libsql/src/test/java/com/dbeaver/jdbc/upd/driver/test/LibSqlDriverTest.java +++ b/com.dbeaver.jdbc.driver.libsql/src/test/java/com/dbeaver/jdbc/upd/driver/test/LibSqlDriverTest.java @@ -17,15 +17,15 @@ package com.dbeaver.jdbc.upd.driver.test; import java.sql.*; -import java.util.Properties; public class LibSqlDriverTest { public static void main(String[] args) throws Exception { long startTime = System.currentTimeMillis(); try { - Properties props = new Properties(); - try (Connection connection = DriverManager.getConnection("jdbc:dbeaver:libsql:" + args[0], props)) { + String databaseUrl = args[0]; + String token = args.length > 1 ? args[1] : null; + try (Connection connection = DriverManager.getConnection("jdbc:dbeaver:libsql:" + databaseUrl, null, token)) { DatabaseMetaData metaData = connection.getMetaData(); System.out.println("Driver: " + metaData.getDriverName()); System.out.println("Database: " + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion()); diff --git a/pom.xml b/pom.xml index b5ffad6..0702d68 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 com.dbeaver.jdbc jdbc-libsql - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT pom DBeaver LibSQL JDBC Project