Skip to content

Commit 179c32d

Browse files
committed
Version beta 0.1 -Ajout de la fonctionnalité de conversion CSV vers SQL
0 parents  commit 179c32d

13 files changed

Lines changed: 2852 additions & 0 deletions

File tree

liste_complete_entreprises_2023_2024.csv

Lines changed: 2774 additions & 0 deletions
Large diffs are not rendered by default.
338 KB
Binary file not shown.

pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.mycompany</groupId>
5+
<artifactId>CSVToSQLConverter</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
<properties>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
<maven.compiler.source>20</maven.compiler.source>
11+
<maven.compiler.target>20</maven.compiler.target>
12+
<exec.mainClass>com.mycompany.csvtosqlconverter.CSVToSQLConverter</exec.mainClass>
13+
</properties>
14+
</project>

src/main/java/CSVReader.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3+
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
4+
*/
5+
6+
/**
7+
*
8+
* @author paulb
9+
*/
10+
class CSVReader {
11+
12+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.mycompany.csvtosqlconverter;
2+
3+
import java.io.BufferedReader;
4+
import java.io.FileReader;
5+
import java.io.IOException;
6+
7+
public class CSVToSQLConverter {
8+
public static void main(String[] args) {
9+
String csvFile = "votre chemin ici";
10+
String line = "";
11+
String cvsSplitBy = ",";
12+
String tableName = "MaTable";
13+
14+
try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) {
15+
String[] columnNames = br.readLine().split(cvsSplitBy);
16+
17+
StringBuilder sql = new StringBuilder("CREATE TABLE " + tableName + " (");
18+
19+
for (String columnName : columnNames) {
20+
sql.append("\n").append(columnName).append(" VARCHAR(255),");
21+
}
22+
23+
sql = new StringBuilder(sql.substring(0, sql.length() - 1) + "\n);");
24+
25+
System.out.println(sql.toString());
26+
27+
while ((line = br.readLine()) != null) {
28+
String[] values = line.split(cvsSplitBy);
29+
30+
sql = new StringBuilder("INSERT INTO " + tableName + " VALUES (");
31+
32+
for (String value : values) {
33+
sql.append("'").append(value).append("', ");
34+
}
35+
36+
sql = new StringBuilder(sql.substring(0, sql.length() - 2) + ");");
37+
38+
System.out.println(sql.toString());
39+
}
40+
41+
} catch (IOException e) {
42+
e.printStackTrace();
43+
}
44+
}
45+
}
3.78 KB
Binary file not shown.

target/classes/CSVReader.class

252 Bytes
Binary file not shown.
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
artifactId=CSVToSQLConverter
2+
groupId=com.mycompany
3+
version=1.0-SNAPSHOT
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CSVReader.class
2+
com\mycompany\csvtosqlconverter\CSVToSQLConverter.class

0 commit comments

Comments
 (0)