Skip to content

Commit abb608c

Browse files
committed
JDBC Into
1 parent 2f52b5a commit abb608c

File tree

10 files changed

+311
-1
lines changed

10 files changed

+311
-1
lines changed

Diff for: java-path-core-databases/pom.xml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>java-path-core</artifactId>
7+
<groupId>gr.codelearn</groupId>
8+
<version>2021.1.0</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>java-path-core-databases</artifactId>
13+
14+
<properties>
15+
<maven.compiler.source>17</maven.compiler.source>
16+
<maven.compiler.target>17</maven.compiler.target>
17+
</properties>
18+
19+
<dependencies>
20+
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
21+
<dependency>
22+
<groupId>com.h2database</groupId>
23+
<artifactId>h2</artifactId>
24+
<version>1.4.200</version>
25+
</dependency>
26+
</dependencies>
27+
28+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import com.thedeanda.lorem.Lorem;
2+
import com.thedeanda.lorem.LoremIpsum;
3+
import org.h2.tools.Server;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
7+
import java.sql.*;
8+
9+
10+
public class DataBaseSimple {
11+
private static final Logger logger = LoggerFactory.getLogger(DataBaseSimple.class);
12+
private static final Lorem generator = LoremIpsum.getInstance();
13+
14+
private static final String DB_CONNECTION_URL_MEMORY_MODE = "jdbc:h2:mem:sample";
15+
private static final String DB_USERNAME = "sa";
16+
private static final String DB_PASSWORD = "";
17+
18+
private static Server server;
19+
20+
public static void main(String[] args) throws Exception {
21+
22+
server = Server.createTcpServer("-tcpAllowOthers", "-tcpDaemon");
23+
server.start();
24+
logger.info("H2 server has started with status '{}'.", server.getStatus());
25+
26+
org.h2.Driver.load();
27+
logger.info("H2 JDBC driver server has been successfully loaded.");
28+
29+
Connection connection = DriverManager.getConnection(DB_CONNECTION_URL_MEMORY_MODE, DB_USERNAME, DB_PASSWORD);
30+
Statement statement = connection.createStatement();
31+
32+
int result = statement.executeUpdate("CREATE TABLE IF NOT EXISTS Registration (" +
33+
" id INTEGER not NULL PRIMARY KEY, " +
34+
" first VARCHAR(20), " +
35+
" last VARCHAR(50), " +
36+
" age INTEGER " +
37+
");"
38+
);
39+
logger.info("Created table command was successful with result {}.", result);
40+
41+
int rowsAffected = statement.executeUpdate("INSERT INTO Registration VALUES (101, 'John', 'Smith', 18)");
42+
logger.info("Update command was successful with {} row(s) affected.", rowsAffected);
43+
44+
ResultSet resultSet = statement.executeQuery("SELECT * FROM Registration");
45+
46+
while (resultSet.next()) {
47+
logger.info("ID: {}, First Name:{}, Last Name:{}, Age: {}",
48+
resultSet.getString("id"),
49+
resultSet.getString("first"),
50+
resultSet.getString("last"),
51+
resultSet.getString("age"));
52+
}
53+
54+
55+
server.stop();
56+
server.shutdown();
57+
logger.info("H2 server has been shutdown.");
58+
}
59+
60+
61+
}
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="WARN" monitorInterval="30">
3+
<Properties>
4+
<Property name="LOG_PATTERN">
5+
%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${hostName} - [%15.15t] %-30.30c{1.} : %m%n%ex
6+
</Property>
7+
</Properties>
8+
9+
<Appenders>
10+
<Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
11+
<PatternLayout pattern="${LOG_PATTERN}"/>
12+
</Console>
13+
14+
<!-- Rolling Random Access File Appender with a default buffer of 256 * 1024 bytes -->
15+
<RollingRandomAccessFile name="RollingRandomAccessFileAppender"
16+
fileName="logs/java-path-core-databases.log"
17+
filePattern="logs/java-path-core-databases-%d{yyyy-MM-dd}.zip">
18+
<PatternLayout>
19+
<Pattern>${LOG_PATTERN}</Pattern>
20+
</PatternLayout>
21+
<Policies>
22+
<TimeBasedTriggeringPolicy/>
23+
</Policies>
24+
<DefaultRolloverStrategy>
25+
<Delete basePath="logs">
26+
<IfLastModified age="30d"/>
27+
</Delete>
28+
</DefaultRolloverStrategy>
29+
</RollingRandomAccessFile>
30+
</Appenders>
31+
32+
<Loggers>
33+
<AsyncLogger name="gr.codelearn" level="debug" additivity="false">
34+
<AppenderRef ref="ConsoleAppender"/>
35+
<AppenderRef ref="RollingRandomAccessFileAppender"/>
36+
</AsyncLogger>
37+
38+
<Root level="info">
39+
<AppenderRef ref="ConsoleAppender"/>
40+
<AppenderRef ref="RollingRandomAccessFileAppender"/>
41+
</Root>
42+
</Loggers>
43+
</Configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package gr.codelearn.core.showcase.oop.collections;
2+
import java.util.ArrayList;
3+
import java.util.Arrays;
4+
import java.util.HashMap;
5+
6+
import static java.util.Arrays.sort;
7+
8+
public class Main {
9+
10+
public static void main(String[] args) {
11+
12+
String[] appsArray = new String[5];
13+
appsArray[0] = "word";
14+
appsArray[1] = "excel";
15+
appsArray[2] = "PowerPoint";
16+
appsArray[3] = "MS Team";
17+
appsArray[4] = "SharePoint";
18+
19+
// for (int i = 0; i < appsArray.length; i++) {
20+
// System.out.println(appsArray[i]);
21+
// }
22+
//
23+
// System.out.println(appsArray[1]);
24+
//
25+
// for(String s : appsArray){
26+
// System.out.println(s);
27+
// }
28+
29+
// float[] arr = new float[3];
30+
// arr[0] = 3.2f;
31+
32+
System.out.println(Arrays.toString(appsArray));
33+
sort(appsArray);
34+
System.out.println(Arrays.toString(appsArray));
35+
36+
// ArrayList
37+
// ArrayList appList = new ArrayList(); // Object
38+
// ArrayList<String> appList = new ArrayList<>();
39+
// appList.add("word");
40+
// appList.add("excel");
41+
// appList.add("powerpoint");
42+
// appList.add(5);
43+
// String ls = (String) appList.get(0);
44+
// System.out.println(appList.get(0));
45+
// System.out.println(appList.get(1));
46+
47+
// for (int i = 0; i < appList.size(); i++) {
48+
// System.out.println(appList.get(i));
49+
// }
50+
//
51+
// for (String s : appList) {
52+
// System.out.println(s);
53+
// }
54+
55+
// System.out.println(appList);
56+
// appList.remove("word");
57+
// appList.remove(0);
58+
// System.out.println(appList);
59+
// System.out.println(appsArray);
60+
61+
// ArrayList<Float> alFloat = new ArrayList<>();
62+
// alFloat.add(12.7f);
63+
// float f = alFloat.get(0);
64+
65+
// String s = new String("Hello");
66+
// Double d = 3.6;
67+
// Double d1 = new Double(5.2);
68+
69+
// HashMap<String, String> appMap = new HashMap<>();
70+
// appMap.put("first", "word");
71+
// appMap.put("second", "excel");
72+
// appMap.put("third", "powerpoint");
73+
// appMap.put("first", "powerpoint");
74+
//
75+
// System.out.println(appMap);
76+
// System.out.println(appMap.get("second"));
77+
//
78+
// for (String key : appMap.keySet()) {
79+
// System.out.println(appMap.get(key));
80+
// }
81+
//
82+
// for(String value : appMap.values()){
83+
// System.out.println(value);
84+
// }
85+
}
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package gr.codelearn.core.showcase.oop.interfaces;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
public class LGControl implements TVControl {
7+
8+
private static final Logger logger = LoggerFactory.getLogger(LGControl.class);
9+
10+
public void on(){
11+
logger.info("LG On");
12+
}
13+
public void off(){
14+
logger.info("LG Off");
15+
}
16+
17+
public void selectChannel(){
18+
logger.info("LG Control ... selects....");
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package gr.codelearn.core.showcase.oop.interfaces;
2+
import org.slf4j.Logger;
3+
import org.slf4j.LoggerFactory;
4+
5+
public class MainInterfaces {
6+
7+
private static final Logger logger = LoggerFactory.getLogger(MainInterfaces.class);
8+
9+
public static void main(String[] args) {
10+
11+
// TVControl tvControl = new TVControl();
12+
// tvControl.off();
13+
14+
// LGControl lgControl = new LGControl();
15+
// lgControl.off();
16+
//
17+
// SamControl samControl = new SamControl();
18+
// samControl.off();
19+
20+
TVControl tvControl = new LGControl();
21+
tvControl.off();
22+
23+
tvControl = new SamControl();
24+
tvControl.off();
25+
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package gr.codelearn.core.showcase.oop.interfaces;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
public class SamControl implements TVControl {
7+
8+
private static final Logger logger = LoggerFactory.getLogger(SamControl.class);
9+
10+
public void on(){
11+
logger.info("Samsung On");
12+
}
13+
public void off(){
14+
logger.info("Samsung Off");
15+
}
16+
17+
public void selectChannel(){
18+
logger.info("Samsung Control ... selects....");
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package gr.codelearn.core.showcase.oop.interfaces;
2+
3+
public class StrangeControl implements TVControl{
4+
@Override
5+
public void on() {
6+
7+
}
8+
9+
@Override
10+
public void off() {
11+
12+
}
13+
14+
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package gr.codelearn.core.showcase.oop.interfaces;
2+
3+
public interface TVControl {
4+
void on();
5+
void off();
6+
7+
default void selectChannel(){
8+
}
9+
}

Diff for: pom.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
<module>java-path-core-basic</module>
2727
<module>java-path-core-maven</module>
2828
<module>java-path-core-oop</module>
29-
</modules>
29+
<module>java-path-core-databases</module>
30+
</modules>
3031

3132
<!-- Properties/Variables -->
3233
<properties>

0 commit comments

Comments
 (0)