-
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.
- Loading branch information
1 parent
103ceb8
commit 80abdc8
Showing
3 changed files
with
61 additions
and
27 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
modules/clients/src/main/java/com/tsurugidb/tsubakuro/examples/handshake/Client.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,60 @@ | ||
package com.tsurugidb.tsubakuro.examples.handshake; | ||
|
||
import java.io.IOException; | ||
|
||
import com.tsurugidb.tsubakuro.exception.ServerException; | ||
import com.tsurugidb.tsubakuro.common.Session; | ||
import com.tsurugidb.tsubakuro.common.SessionBuilder; | ||
import com.tsurugidb.tsubakuro.sql.SqlClient; | ||
import com.tsurugidb.tsubakuro.sql.Transaction; | ||
import com.tsurugidb.tsubakuro.sql.Placeholders; | ||
import com.tsurugidb.tsubakuro.sql.Parameters; | ||
|
||
public final class Client { | ||
// this example requires tsurugi.ini that has prepare_test_tables=true entry in sql section. | ||
public static void doClient(String url) throws IOException, ServerException, InterruptedException { | ||
try (Session session = SessionBuilder.connect(url).withLabel("exampleLabel").withApplicationName("exampleApplication").create(); | ||
SqlClient sqlClient = SqlClient.attach(session); | ||
Transaction transaction = sqlClient.createTransaction().get()) { | ||
|
||
var resultSet = transaction.executeQuery("SELECT * FROM T0").get(); | ||
var metadata = resultSet.getMetadata().getColumns(); | ||
|
||
int count = 0; | ||
while (resultSet.nextRow()) { | ||
int columnIndex = 0; | ||
while (resultSet.nextColumn()) { | ||
if (!resultSet.isNull()) { | ||
switch (metadata.get(columnIndex).getAtomType()) { | ||
case INT4: | ||
resultSet.fetchInt4Value(); | ||
break; | ||
case INT8: | ||
resultSet.fetchInt8Value(); | ||
break; | ||
case FLOAT4: | ||
resultSet.fetchFloat4Value(); | ||
break; | ||
case FLOAT8: | ||
resultSet.fetchFloat8Value(); | ||
break; | ||
case CHARACTER: | ||
resultSet.fetchCharacterValue(); | ||
break; | ||
default: | ||
throw new IOException("the column type is invalid"); | ||
} | ||
} | ||
columnIndex++; | ||
} | ||
count++; | ||
} | ||
|
||
transaction.commit().get(); | ||
} | ||
|
||
} | ||
|
||
private Client() { | ||
} | ||
} |
26 changes: 0 additions & 26 deletions
26
modules/clients/src/main/java/com/tsurugidb/tsubakuro/examples/handshake/CreateTable.java
This file was deleted.
Oops, something went wrong.
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