Skip to content

Commit

Permalink
#4 - Code sample
Browse files Browse the repository at this point in the history
- Version bump
- Connection failure handle fix
- Auth parameter pass fix
  • Loading branch information
serge-rider committed Nov 7, 2024
1 parent a50252b commit 496fac7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 9 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion com.dbeaver.jdbc.driver.libsql/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion com.dbeaver.jdbc.driver.libsql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.dbeaver.jdbc</groupId>
<artifactId>jdbc-libsql</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.3-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>com.dbeaver.jdbc.driver.libsql</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Check warning on line 68 in com.dbeaver.jdbc.driver.libsql/src/main/java/com/dbeaver/jdbc/driver/libsql/LibSqlConnection.java

View workflow job for this annotation

GitHub Actions / Check / Lint

[checkstyle] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./com.dbeaver.jdbc.driver.libsql/src/main/java/com/dbeaver/jdbc/driver/libsql/LibSqlConnection.java:68:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check warning on line 22 in com.dbeaver.jdbc.driver.libsql/src/test/java/com/dbeaver/jdbc/upd/driver/test/LibSqlDriverTest.java

View workflow job for this annotation

GitHub Actions / Check / Lint

[checkstyle] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./com.dbeaver.jdbc.driver.libsql/src/test/java/com/dbeaver/jdbc/upd/driver/test/LibSqlDriverTest.java:22:5: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
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());
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.dbeaver.jdbc</groupId>
<artifactId>jdbc-libsql</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.3-SNAPSHOT</version>

<packaging>pom</packaging>
<name>DBeaver LibSQL JDBC Project</name>
Expand Down

0 comments on commit 496fac7

Please sign in to comment.