[Add] lib to create database

This commit is contained in:
tiennm99 committed 2023-10-30 07:35:55 +07:00
1 parent 17e238a76b
commit 2d2850f20f
126 files changed
+140 -20

No files matched your search

+2
View File
@@ -1,4 +1,6 @@
.idea
*.trace.db
/logs
.gradle
build/
+9
View File
@@ -10,9 +10,18 @@ repositories {
}
dependencies {
annotationProcessor("org.projectlombok:lombok:1.18.30")
compileOnly("org.projectlombok:lombok:1.18.30")
implementation("com.h2database:h2:2.2.224")
implementation("org.apache.logging.log4j:log4j-core:2.21.1")
implementation("org.apache.logging.log4j:log4j-slf4j2-impl:2.21.1")
implementation("org.apache.poi:poi:5.2.4")
implementation("org.apache.poi:poi-ooxml:5.2.4")
implementation("org.hibernate.orm:hibernate-core:6.3.1.Final")
implementation("org.slf4j:slf4j-api:2.0.9")
testAnnotationProcessor("org.projectlombok:lombok:1.18.30")
testCompileOnly("org.projectlombok:lombok:1.18.30")
testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
}
-20
View File
@@ -1,20 +0,0 @@
package dev.miti99;
// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
// then press Enter. You can now see whitespace characters in your code.
public class Main {
public static void main(String[] args) {
// Press Alt+Enter with your caret at the highlighted text to see how
// IntelliJ IDEA suggests fixing it.
System.out.printf("Hello and welcome!");
// Press Shift+F10 or click the green arrow button in the gutter to run the code.
for (int i = 1; i <= 5; i++) {
// Press Shift+F9 to start debugging your code. We have set one breakpoint
// for you, but you can always add more by pressing Ctrl+F8.
System.out.println("i = " + i);
}
}
}
@@ -0,0 +1,32 @@
package dev.miti99.thptqg2017;
import dev.miti99.thptqg2017.entity.Student;
import java.text.SimpleDateFormat;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.cfg.Configuration;
@Slf4j
public class Converter {
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
public static void main(String[] args) {
var configuration = new Configuration();
configuration.configure("hibernate.cfg.xml");
try (var sessionFactory = configuration.buildSessionFactory();
var session = sessionFactory.openSession()) {
var transaction = session.beginTransaction();
var newStudent = new Student();
newStudent.setSoBaoDanh(12345);
newStudent.setHoTen("John Doe");
newStudent.setNgaySinh(dateFormat.parse("01/01/1999"));
session.merge(newStudent);
transaction.commit();
} catch (Exception e) {
log.error("Exception occurred", e);
}
}
}
@@ -0,0 +1,59 @@
package dev.miti99.thptqg2017.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import java.util.Date;
import lombok.Data;
@Entity
@Table(name = "Student")
@Data
public class Student {
@Id
@Column(name = "SOBAODANH")
private int soBaoDanh;
@Column(name = "HO_TEN")
private String hoTen;
@Column(name = "NGAY_SINH")
@Temporal(TemporalType.TIMESTAMP)
private Date ngaySinh;
@Column(name = "TOAN")
private double toan;
@Column(name = "NGU_VAN")
private double nguVan;
@Column(name = "VAT_LY")
private double vatLy;
@Column(name = "HOA_HOC")
private double hoaHoc;
@Column(name = "SINH_HOC")
private double sinhHoc;
@Column(name = "KHTN")
private double khtn;
@Column(name = "LICH_SU")
private double lichSu;
@Column(name = "DIA_LY")
private double diaLy;
@Column(name = "GDCD")
private double gdcd;
@Column(name = "KHXH")
private double khxh;
@Column(name = "TIENG_ANH")
private double tiengAnh;
}
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.h2.Driver</property>
<property name="hibernate.connection.url">jdbc:h2:./database</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="show_sql">false</property>
<mapping class="dev.miti99.thptqg2017.entity.Student" />
</session-factory>
</hibernate-configuration>
+20
View File
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<File fileName="logs/application.log" name="File">
<PatternLayout
pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
<AppenderRef ref="File"/>
</Root>
</Loggers>
</Configuration>
Loaded 100 of 126 files, more files were not shown because too many files have changed in this diff. Show more