Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
saaya-code committed Mar 18, 2024
0 parents commit 435f201
Show file tree
Hide file tree
Showing 32 changed files with 1,262 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/sqldialects.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions TP_Base.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/libs/mysql-connector-java-5.0.7-bin.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
Binary file added libs/mysql-connector-java-5.0.7-bin.jar
Binary file not shown.
99 changes: 99 additions & 0 deletions src/ExercicesTP/CRUD/FormationDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package ExercicesTP.CRUD;

import ExercicesTP.Formation;
import ExercicesTP.Config;
import TP_Base.MyConnexion;
import ExercicesTP.interfaces.FormationDaoCRUD;
import java.sql.*;

public class FormationDAO implements FormationDaoCRUD {

Connection con = null;
Statement st = null;
public FormationDAO() {
con = MyConnexion.getConnection(Config.URL, Config.USERNAME, Config.PASSWORD);
try {
st = con.createStatement();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public void addFormation(Formation formation) {
PreparedStatement ps = null;
try {
ps = con.prepareStatement("INSERT INTO formation (idF, titre, datef, lieu, certif) VALUES (?,?,?,?,?)");
ps.setInt(1, formation.getId());
ps.setString(2, formation.getTitle());
ps.setDate(3, formation.getDateF());
ps.setString(4, formation.getLieu());
ps.setBoolean(5, formation.getCertification());
ps.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}

public void deleteFormation(int id) {
try {
st.executeUpdate("DELETE FROM formation WHERE Id = " + id);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}

public void updateFormation(Formation formation) {
PreparedStatement ps = null;
try {
ps = con.prepareStatement("UPDATE formation SET titre = ?, datef = ?, lieu = ?, certification = ? WHERE Id = ?");
ps.setString(1, formation.getTitle());
ps.setDate(2, formation.getDateF());
ps.setString(3, formation.getLieu());
ps.setBoolean(4, formation.getCertification());
ps.setInt(5, formation.getId());
ps.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException(e);
}

}

public Formation getFormation(int id) {
try {
PreparedStatement ps = con.prepareStatement("SELECT * FROM formation WHERE IdF = ?");
ps.setInt(1, id);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return new Formation(rs.getInt(1), rs.getString(2), rs.getDate(4), rs.getString(3), rs.getBoolean(5));
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return null;
}

public Formation[] getAllFormations() {
try {
ResultSet rs = st.executeQuery("SELECT * FROM formation");
Formation[] formations = new Formation[getRowCount(rs)];
int i = 0;
while (rs.next()) {
formations[i] = new Formation(rs.getInt(1), rs.getString(2), rs.getDate(3), rs.getString(4), rs.getBoolean(5));
i++;
}
return formations;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}

private int getRowCount(ResultSet rs) {
try {
int rowCount = 0;
while(rs.next())
rowCount++;
return rowCount;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
7 changes: 7 additions & 0 deletions src/ExercicesTP/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ExercicesTP;

public class Config {
public static final String USERNAME = "root";
public static final String PASSWORD = "";
public static final String URL = "jdbc:mysql://127.0.0.1/GFormations";
}
27 changes: 27 additions & 0 deletions src/ExercicesTP/Enseignant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ExercicesTP;

public class Enseignant extends Personne{
String specialite;
String grade;
public Enseignant(int Id, String nom, String prenom, String specialite, String grade) {
super(Id, nom, prenom);
this.specialite = specialite;
this.grade = grade;
}

public String getGrade() {
return grade;
}

public void setGrade(String grade) {
this.grade = grade;
}

public String getSpecialite() {
return specialite;
}

public void setSpecialite(String specialite) {
this.specialite = specialite;
}
}
Loading

0 comments on commit 435f201

Please sign in to comment.