- Notifications
You must be signed in to change notification settings - Fork1
The library provides mysql (CRUD), socket server, logging.
License
NotificationsYou must be signed in to change notification settings
RayTW/RA
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
The library provides mysql (CRUD), socket server, logging.
You can download a jar from GitHub'sreleases page.
Or use Gradle:
repositories { mavenCentral()}dependencies { implementation'io.github.raytw:ra:0.7.0'}
Download the BigQueryJDBC 4.2-compatible file.
Import the library(GoogleBigQueryJDBC42.jar) to the java build path.
dependencies { implementation'io.github.raytw:ra:0.7.0' implementation'com.google.cloud:google-cloud-bigquery:2.16.1'}
dependencies { implementation'io.github.raytw:ra:0.7.0' implementation'com.google.cloud:google-cloud-spanner-jdbc:2.7.9'}
Once connection (OnceConnection)
MysqlParameters.Builderbuilder =MysqlParameters.newBuilder() .setHost("127.0.0.1") .setName("test") .setPort(3306) .setUser("ray") .setPassword("raypwd");try (DatabaseConnectionconnection =newOnceConnection(builder.build())) {// auto close connection.RecordCursorrecord =connection.createStatementExecutor().executeQuery("SELECT * FROM `test_table`");record .stream() .forEach(row -> {System.out.println("name = " +row.getInt("id") +row.getString("name")); }); }catch (Exceptione) {e.printStackTrace(); }
Keep-alive connection and connection pool. (DatabaseConnections)
MysqlParameters.Builderbuilder =MysqlParameters.newBuilder() .setHost("127.0.0.1") .setName("test") .setPort(3306) .setUser("ray") .setPassword("raypwd");DatabaseConnectionspool =newDatabaseConnections();intconnectionSize =5;pool.connectOriginalConnection(builder.build(),connectionSize);for (inti =0;i <connectionSize;i++) {RecordCursorrecord =pool.next().executeQuery("SELECT * FROM `test_table` LIMIT 1");longid =record.fieldLong("id");Stringname =record.field("name");System.out.println("id = " +id +", name" +name); }
Once connection (OnceConnection)
try (OnceConnectionconnection =newOnceConnection(newH2Parameters.Builder() .inMemory() .setName("databaseName") .setProperties("DATABASE_TO_UPPER","false") .setProperties("MODE","MYSQL") .build())) {connection.connect();StatementExecutorexecutor =connection.createStatementExecutor();StringcreateTableSql ="CREATE TABLE `test_table` (" +" `id` bigint auto_increment," +" `col_int` int(10) UNSIGNED NOT NULL," +" `col_double` DOUBLE UNSIGNED DEFAULT NULL," +" `col_boolean` BOOLEAN DEFAULT NULL ," +" `col_tinyint` tinyint(1) NOT NULL ," +" `col_enum` enum('default','enum1','enum2') DEFAULT NULL ," +" `col_decimal` decimal(20,3) DEFAULT 0.000 ," +" `col_varchar` varchar(50) NOT NULL ," +" `created_at` timestamp NOT NULL DEFAULT current_timestamp()," +" `updated_at` timestamp NOT NULL DEFAULT current_timestamp() " +"ON UPDATE current_timestamp()" +");";executor.executeUpdate(createTableSql);Stringsql ="INSERT INTO test_table SET col_int=1" +",col_double=1.01" +",col_boolean=true" +",col_tinyint=5" +",col_enum='enum1'" +",col_decimal=1.1111" +",col_varchar='col_varchar'" +",created_at=NOW();";executor.executeUpdate(sql);RecordCursorrecord =executor.executeQuery("SELECT * FROM `test_table`");record .stream() .forEach(row -> {System.out.println("col_int=" +row.getInt("col_int")); });executor.executeUpdate("DROP TABLE test_table"); }
try (OnceConnectionconnection =newOnceConnection(newH2Parameters.Builder() .inMemory() .setName("databaseName") .setProperties("DATABASE_TO_UPPER","false") .setProperties("MODE","MYSQL") .build())) {connection.connect();StatementExecutorexecutor =connection.createStatementExecutor();StringcreateTableSql ="CREATE TABLE `test_table` (" +" `id` bigint auto_increment," +" `age` int(10) UNSIGNED NOT NULL," +" `name` VARCHAR(100) DEFAULT NULL" +");";executor.executeUpdate(createTableSql);Stringsql ="INSERT INTO test_table SET age=?" +",name=?;";executor.prepareExecuteUpdate(Prepared.newBuilder(sql) .set(1,ParameterValue.int64(18)) .set(2,ParameterValue.string("ray")) .build());executor.prepareExecuteUpdate(Prepared.newBuilder(sql) .set(1,ParameterValue.int64(22)) .set(2,ParameterValue.string("name test")) .build());RecordCursorrecord =executor.prepareExecuteQuery(Prepared.newBuilder("SELECT * FROM `test_table` WHERE name = ? LIMIT 1;") .set(1,ParameterValue.string("ray")) .build());System.out.println("name=" +record.field("name") +", age=" +record.fieldInt("age"));executor.executeUpdate("DROP TABLE test_table"); }
Ray Li - @raytw on GitHub, Kevin - @tsaibiido on GitHub
MIT. See theLICENSE file for details.
About
The library provides mysql (CRUD), socket server, logging.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.