File tree Expand file tree Collapse file tree 6 files changed +46
-9
lines changed
com.dbeaver.jdbc.driver.libsql
main/java/com/dbeaver/jdbc/driver/libsql
test/java/com/dbeaver/jdbc/upd/driver/test Expand file tree Collapse file tree 6 files changed +46
-9
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,30 @@ Token based authentication supported in version 1.0. Pass token value as passwor
2121
2222Driver class name: ` com.dbeaver.jdbc.driver.libsql.LibSqlDriver `
2323
24+ ## Example
25+
26+ ``` java
27+ import java.sql.* ;
28+
29+ public class LibSqlTest {
30+ public static void main (String [] args ) throws Exception {
31+ String databaseUrl = " http://libsql-server.company.local:8080" ;
32+ try (Connection connection = DriverManager . getConnection(" jdbc:dbeaver:libsql:" + databaseUrl)) {
33+ try (Statement statement = connection. createStatement()) {
34+ statement. execute(" drop table if exists test_table_1" );
35+ statement. execute(" create table test_table_1 (id integer, name string)" );
36+ statement. execute(" insert into test_table_1 values(1, 'test one')" );
37+ statement. execute(" insert into test_table_1 values(2, 'test two')" );
38+ try (ResultSet rs = statement. executeQuery(" select * from test_table_1" )) {
39+ while (rs. next()) {
40+ System . out. println(rs. getInt(" id" ) + " = " + rs. getString(" name" ));
41+ }
42+ }
43+ }
44+ }
45+ }
46+ }
47+ ```
2448## License
2549
2650Licensed under the [ Apache License, Version 2.0] ( http://www.apache.org/licenses/LICENSE-2.0 )
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ Manifest-Version: 1.0
22Bundle-ManifestVersion : 2
33Bundle-Name : DBeaver LibSQL JDBC Driver
44Bundle-SymbolicName : com.dbeaver.jdbc.driver.libsql
5- Bundle-Version : 1.0.2 .qualifier
5+ Bundle-Version : 1.0.3 .qualifier
66Bundle-Release-Date : 20230522
77Bundle-RequiredExecutionEnvironment : JavaSE-17
88Export-Package : com.dbeaver.jdbc.driver.libsql,
Original file line number Diff line number Diff line change 77 <parent >
88 <groupId >com.dbeaver.jdbc</groupId >
99 <artifactId >jdbc-libsql</artifactId >
10- <version >1.0.2 -SNAPSHOT</version >
10+ <version >1.0.3 -SNAPSHOT</version >
1111 <relativePath >../pom.xml</relativePath >
1212 </parent >
1313 <artifactId >com.dbeaver.jdbc.driver.libsql</artifactId >
Original file line number Diff line number Diff line change @@ -51,15 +51,23 @@ public LibSqlConnection(
5151 this .driverProperties = driverProperties ;
5252
5353 try {
54- String token = CommonUtils .toString (driverProperties .get ("password" ));
54+ String token = CommonUtils .toString (driverProperties .get ("password" ), null );
5555 this .client = new LibSqlClient (new URL (url ), token );
5656 } catch (IOException e ) {
5757 throw new SQLException (e );
5858 }
59- // Verify connection
60- LibSqlUtils .executeQuery (this , "SELECT 1" );
59+ try {
60+ // Verify connection
61+ LibSqlUtils .executeQuery (this , "SELECT 1" );
62+ } catch (Exception e ) {
63+ close ();
64+ throw e ;
65+ }
6166 }
6267
68+ /**
69+ * Obtain transport client
70+ */
6371 public LibSqlClient getClient () {
6472 String applicationName = getClientApplicationName ();
6573 if (!CommonUtils .isEmpty (applicationName )) {
Original file line number Diff line number Diff line change 1717package com .dbeaver .jdbc .upd .driver .test ;
1818
1919import java .sql .*;
20- import java .util .Properties ;
2120
2221public class LibSqlDriverTest {
22+ /**
23+ * Runs simple select query in LibSQL
24+ *
25+ * @param args mvn exec:java "-Dexec.args=database-url [token]"
26+ */
2327 public static void main (String [] args ) throws Exception {
2428 long startTime = System .currentTimeMillis ();
2529
2630 try {
27- Properties props = new Properties ();
28- try (Connection connection = DriverManager .getConnection ("jdbc:dbeaver:libsql:" + args [0 ], props )) {
31+ String databaseUrl = args [0 ];
32+ String token = args .length > 1 ? args [1 ] : null ;
33+ try (Connection connection = DriverManager .getConnection ("jdbc:dbeaver:libsql:" + databaseUrl , null , token )) {
2934 DatabaseMetaData metaData = connection .getMetaData ();
3035 System .out .println ("Driver: " + metaData .getDriverName ());
3136 System .out .println ("Database: " + metaData .getDatabaseProductName () + " " + metaData .getDatabaseProductVersion ());
Original file line number Diff line number Diff line change 66 <modelVersion >4.0.0</modelVersion >
77 <groupId >com.dbeaver.jdbc</groupId >
88 <artifactId >jdbc-libsql</artifactId >
9- <version >1.0.2 -SNAPSHOT</version >
9+ <version >1.0.3 -SNAPSHOT</version >
1010
1111 <packaging >pom</packaging >
1212 <name >DBeaver LibSQL JDBC Project</name >
You can’t perform that action at this time.
0 commit comments