Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #2

Merged
merged 12 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ target/

### IntelliJ IDEA ###
.idea/
/.idea/
*.iws
*.iml
*.ipr
Expand Down Expand Up @@ -32,4 +33,6 @@ build/
.vscode/

### Mac OS ###
.DS_Store
.DS_Store
/mysql-data/
!/mysql-data/
190 changes: 0 additions & 190 deletions .idea/workspace.xml

This file was deleted.

31 changes: 31 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
version: "3.8"

services:
# MYSQL
db:
image: mysql
container_name: mysqldb
ports:
- 3306:3306
volumes:
- ./mysql-data:/var/lib/mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: p@ssw0rdOCR
MYSQL_DATABASE: openocrdb
MYSQL_USER: dba
MYSQL_PASSWORD: dbaPass

# adminer:
# image: adminer
# container_name: database_adminer
# restart: always
# ports:
# - 8080:8080

volumes:
data: {}
networks:
default:
name: openOCR_database_default
Binary file added lib/mysql-connector-j-8.0.31.jar
Binary file not shown.
Binary file added lib/mysql-connector-java-8.0.25.jar
Binary file not shown.
Binary file added lib/mysql-connector-java-8.0.27.jar
Binary file not shown.
Binary file added lib/mysql-connector-java-8.0.30.jar
Binary file not shown.
Binary file added lib/protobuf-java-3.11.4.jar
Binary file not shown.
Binary file added lib/protobuf-java-3.19.4.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.29</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand All @@ -47,4 +52,6 @@
</plugin>
</plugins>
</build>


</project>
6 changes: 6 additions & 0 deletions sql.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
create table files
(
id_file int auto_increment
primary key,
fichier LONGBLOB NOT NULL
);
22 changes: 22 additions & 0 deletions src/main/java/com/example/openocr/Database.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.openocr;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Database {
public static Connection connectDatabase() {
Connection connect = null;
String url = "jdbc:mysql://localhost:3306/openocrdb"; // "jdbc:mysql://localhost:3306/mydatabase?useSSL=false";
String user = "dba";
String password = "dbaPass"; // "david123";
try {
Class.forName("com.mysql.cj.jdbc.Driver");
connect = DriverManager.getConnection(url, user, password);
System.out.println("connexion établie.");
} catch (ClassNotFoundException | SQLException e) {
System.out.println("erreur de connexion !" + e);
}
return connect;
}
}
18 changes: 0 additions & 18 deletions src/main/java/com/example/openocr/HelloServlet.java

This file was deleted.

39 changes: 39 additions & 0 deletions src/main/java/com/example/openocr/Process.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.example.openocr;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Process {

private static final String saveFile = "INSERT INTO files (fichier) values (?)";

public int saveFileDatabase(InputStream file) {
Connection connect = Database.connectDatabase();
System.out.println(connect);

int row = 0;

try {
PreparedStatement pr = connect.prepareStatement(saveFile);

if (file != null) {
pr.setBlob(1, file);
}

// send file to database
row = pr.executeUpdate();

} catch (SQLException e) {
throw new RuntimeException(e);
}

return row;
}

public static void main(String[] args) {
Connection connect = Database.connectDatabase();
System.out.println(connect);
}
}
Loading