Compare commits

...

10 commits

Author SHA1 Message Date
cb14209e59 prototypes de classes sql
prototypes pour les classes User et Requests, à ajouter dans la bdd insa après
2024-10-09 16:51:54 +02:00
3fda4f07ff Transférer les fichiers vers 'projet_maven/src/main/java' 2024-10-09 16:47:54 +02:00
12fbf1601f Transférer les fichiers vers 'projet_maven/target/classes' 2024-10-09 16:46:38 +02:00
b897e4f6a9 Supprimer 'projet_maven/target/createdFiles.lst' 2024-10-09 16:45:58 +02:00
676118c827 Supprimer 'projet_maven/target/pom.properties' 2024-10-09 16:45:49 +02:00
ac22db6ead Supprimer 'projet_maven/target/Main.class' 2024-10-09 16:45:42 +02:00
277669320e Supprimer 'projet_maven/target/InsertUser.class' 2024-10-09 16:45:22 +02:00
963e9d680e projet maven 2024-10-09 16:45:12 +02:00
fff750c96f projet maven 2024-10-09 16:44:23 +02:00
980d4a00f3 projet maven
tout le dossier du projet maven avec mes fichiers
- Sami
2024-10-09 16:42:16 +02:00
13 changed files with 212 additions and 0 deletions

View file

@ -0,0 +1,8 @@
CREATE TABLE Requests (
request_id INT AUTO_INCREMENT NOT NULL,
title VARCHAR(30) NOT NULL,
content VARCHAR(500) NOT NULL,
user_id INT;
PRIMARY KEY (request_id)
FOREIGN KEY (user_id) REFERENCES Users(user_id)
);

15
fichiers_sql/Users.sql Normal file
View file

@ -0,0 +1,15 @@
CREATE TABLE Users (
user_id INT AUTO_INCREMENT NOT NULL,
nom VARCHAR(100) NOT NULL,
user_role VARCHAR(20) NOT NULL,
PRIMARY KEY (user_id)
CHECK (user_role IN ("DEMANDEUR", "BENEVOLE", "VALIDATEUR")) /*pour eviter que le role soit n'importe quoi*/
);
INSERT INTO user (nom, user_role) VALUES ("Tom Cruise", "DEMANDEUR");
INSERT INTO user (nom, user_role) VALUES ("Omar Sy", "DEMANDEUR");
INSERT INTO user (nom, user_role) VALUES ("Emma Stone", "DEMANDEUR");
INSERT INTO user (nom, user_role) VALUES ("Margot Robbie", "BENEVOLE");
INSERT INTO user (nom, user_role) VALUES ("Vincent Cassel", "BENEVOLE");
INSERT INTO user (nom, user_role) VALUES ("Michael Jackson", "BENEVOLE");
INSERT INTO user (nom, user_role) VALUES ("Staff_Purpan", "VALIDATEUR");

40
projet_maven/.classpath Normal file
View file

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-23">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

23
projet_maven/.project Normal file
View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ProjetPDLA</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=23
org.eclipse.jdt.core.compiler.compliance=23
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=23

View file

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

2
projet_maven/codebdd.txt Normal file
View file

@ -0,0 +1,2 @@
cmd: mysql -h srv-bdens.insa-toulouse.fr --port=3306 -u projet_gei_023 -p projet_gei_023
mdp: ohQu4ood

55
projet_maven/pom.xml Normal file
View file

@ -0,0 +1,55 @@
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.insa.maven.pdla</groupId>
<artifactId>ProjetPDLA</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.source>23</maven.compiler.source>
<maven.compiler.target>23</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>9.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>fr.pdla.demo.HelloClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,30 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class InsertUser {
// /!\ PROTOTYPE A MODIFIER SUIVANT FORMAT FINAL DE LA BDD /!\
// fonction qui insere l'user dans la bdd insa
public static void insertUser(String nom, String user_role) {
// pour se connecter a la bdd
String url = "jdbc:mysql://srv-bdens.insa-toulouse.fr:3306/projet_gei_023"; // url sur moodle
String user = "projet_gei_023"; // login
String password = "ohQu4ood"; // mdp sur liste binomes
try (Connection connection = DriverManager.getConnection(url, user, password)) {
Statement stmt = connection.createStatement();
// on cree requete SQL avec entrees user
String insertQuery = "INSERT INTO User(nom, user_role) VALUES ('" + nom + "', '" + user_role + "')";
// on fait la requete
stmt.executeUpdate(insertQuery);
System.out.println("Ligne insérée avec succès.");
} catch (SQLException e) {
System.err.println("Echec de l'insertion : " + e.getMessage());
}
}
}

View file

@ -0,0 +1,27 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
//on active le scanner pour recuperer les entrees user
Scanner scanner = new Scanner(System.in);
try {
// on demande nom et role de l'user
System.out.print("Entrez votre nom d'utilisateur (100 caractères max): "); // modifier le nb de caracteres max suivant bdd
String nom = scanner.nextLine();
System.out.print("Entrez votre rôle (DEMANDEUR, BENEVOLE, VALIDATEUR) : ");
String user_role = scanner.nextLine();
// on insere dans la table user dans la base de donnees insa
InsertUser.insertUser(nom, user_role);
} finally {
//on libere le scanner meme si l'insertion a echoue (d'ou le bloc try/finally)
scanner.close();
}
}
}
//code a changer parce que s'il y a une erreur on doit relancer la connection à chaque fois au lieu de juste redemander

Binary file not shown.

Binary file not shown.

Binary file not shown.