2021-08-05
This commit is contained in:
15
jdbc-sqlite/build.gradle.kts
Normal file
15
jdbc-sqlite/build.gradle.kts
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Examples for Java
|
||||
*
|
||||
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||
* https://www.elex-project.com/
|
||||
*/
|
||||
|
||||
plugins {
|
||||
id("elex-java")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
runtimeOnly ("org.xerial:sqlite-jdbc:3.36.0.1")
|
||||
}
|
||||
20
jdbc-sqlite/logback.xml
Normal file
20
jdbc-sqlite/logback.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Examples for Java
|
||||
~
|
||||
~ Copyright (c) 2021. Elex. All Rights Reserved.
|
||||
~ https://www.elex-project.com/
|
||||
-->
|
||||
|
||||
<configuration>
|
||||
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="TRACE">
|
||||
<appender-ref ref="CONSOLE" />
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Examples for Java
|
||||
*
|
||||
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||
* https://www.elex-project.com/
|
||||
*/
|
||||
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
@Slf4j
|
||||
public class JdbcSample {
|
||||
public static void main(String... args) throws SQLException {
|
||||
Connection conn = DriverManager.getConnection("jdbc:sqlite:test.db");
|
||||
|
||||
Statement stat = conn.createStatement();
|
||||
stat.executeUpdate("drop table if exists people;");
|
||||
stat.executeUpdate("create table people (name, occupation);");
|
||||
|
||||
PreparedStatement prep = conn.prepareStatement("insert into people values (?, ?);");
|
||||
|
||||
prep.setString(1, "Gandhi");
|
||||
prep.setString(2, "politics");
|
||||
prep.addBatch();
|
||||
prep.setString(1, "Turing");
|
||||
prep.setString(2, "computers");
|
||||
prep.addBatch();
|
||||
prep.setString(1, "Wittgenstein");
|
||||
prep.setString(2, "smartypants");
|
||||
prep.addBatch();
|
||||
|
||||
conn.setAutoCommit(false);
|
||||
prep.executeBatch();
|
||||
conn.setAutoCommit(true);
|
||||
|
||||
|
||||
ResultSet rs = stat.executeQuery("select * from people;");
|
||||
while (rs.next()) {
|
||||
System.out.println("name = " + rs.getString("name"));
|
||||
System.out.println("job = " + rs.getString("occupation"));
|
||||
}
|
||||
rs.close();
|
||||
conn.close();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* Examples for Java
|
||||
*
|
||||
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||
* https://www.elex-project.com/
|
||||
*/
|
||||
|
||||
package kr.pe.elex.examples;
|
||||
Reference in New Issue
Block a user