-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a getTableNames() and getTableMetadata() example
- Loading branch information
1 parent
1f8df21
commit 4b29e09
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
modules/clients/src/main/java/com/tsurugidb/tsubakuro/examples/tables/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.tsurugidb.tsubakuro.examples.tables; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
import com.tsurugidb.tsubakuro.exception.ServerException; | ||
import com.tsurugidb.tsubakuro.channel.common.connection.UsernamePasswordCredential; | ||
import com.tsurugidb.tsubakuro.common.Session; | ||
import com.tsurugidb.tsubakuro.common.SessionBuilder; | ||
import com.tsurugidb.tsubakuro.sql.SqlClient; | ||
|
||
public final class Main { | ||
private Main(String[] args) { | ||
} | ||
|
||
// set dbname as follows | ||
// -Ptsurugi.dbname=ipc:tsurugi or | ||
// -Ptsurugi.dbname=tcp://localhost:12345 | ||
// when run this example by `./gradlew run` command | ||
private static String url = System.getProperty("tsurugi.dbname"); | ||
|
||
public static void main(String[] args) { | ||
try ( | ||
Session session = SessionBuilder.connect(url) | ||
.withCredential(new UsernamePasswordCredential("user", "pass")) | ||
.create(10, TimeUnit.SECONDS); | ||
SqlClient sqlClient = SqlClient.attach(session)) { | ||
|
||
var tableList = sqlClient.listTables().get(); | ||
for (var t : tableList.getTableNames()) { | ||
var metadata = sqlClient.getTableMetadata(t).get(); | ||
System.out.println("---- table name = " + t + " ----"); | ||
for (var c : metadata.getColumns()) { | ||
System.out.println("column = " + c); | ||
System.out.println(); | ||
} | ||
} | ||
|
||
} catch (Exception e) { | ||
System.err.println(e); | ||
} | ||
} | ||
} |