-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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> |
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); | ||
} | ||
} | ||
} |
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"; | ||
} |
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; | ||
} | ||
} |