V2 funcha
This commit is contained in:
parent
07f93f329f
commit
41dd372a13
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
/build/
|
||||
/dist/
|
||||
/nbproject/private/
|
||||
|
@ -43,7 +43,7 @@ j2ee.compile.on.save=true
|
||||
j2ee.copy.static.files.on.save=true
|
||||
j2ee.deploy.on.save=true
|
||||
j2ee.platform=1.7-web
|
||||
j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-ssi.jar:${j2ee.server.home}/lib/catalina-storeconfig.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.20.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jakartaee-migration-1.0.0-shaded.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jaspic-api.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-cs.jar:${j2ee.server.home}/lib/tomcat-i18n-de.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-i18n-ko.jar:${j2ee.server.home}/lib/tomcat-i18n-pt-BR.jar:${j2ee.server.home}/lib/tomcat-i18n-ru.jar:${j2ee.server.home}/lib/tomcat-i18n-zh-CN.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-jni.jar:${j2ee.server.home}/lib/tomcat-util-scan.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar
|
||||
j2ee.platform.classpath=${j2ee.server.domain}/lib/annotations-api.jar:${j2ee.server.domain}/lib/catalina-ant.jar:${j2ee.server.domain}/lib/catalina-ha.jar:${j2ee.server.domain}/lib/catalina-ssi.jar:${j2ee.server.domain}/lib/catalina-storeconfig.jar:${j2ee.server.domain}/lib/catalina-tribes.jar:${j2ee.server.domain}/lib/catalina.jar:${j2ee.server.domain}/lib/ecj-4.20.jar:${j2ee.server.domain}/lib/el-api.jar:${j2ee.server.domain}/lib/jakartaee-migration-1.0.0-shaded.jar:${j2ee.server.domain}/lib/jasper-el.jar:${j2ee.server.domain}/lib/jasper.jar:${j2ee.server.domain}/lib/jaspic-api.jar:${j2ee.server.domain}/lib/jsp-api.jar:${j2ee.server.domain}/lib/servlet-api.jar:${j2ee.server.domain}/lib/tomcat-api.jar:${j2ee.server.domain}/lib/tomcat-coyote.jar:${j2ee.server.domain}/lib/tomcat-dbcp.jar:${j2ee.server.domain}/lib/tomcat-i18n-cs.jar:${j2ee.server.domain}/lib/tomcat-i18n-de.jar:${j2ee.server.domain}/lib/tomcat-i18n-es.jar:${j2ee.server.domain}/lib/tomcat-i18n-fr.jar:${j2ee.server.domain}/lib/tomcat-i18n-ja.jar:${j2ee.server.domain}/lib/tomcat-i18n-ko.jar:${j2ee.server.domain}/lib/tomcat-i18n-pt-BR.jar:${j2ee.server.domain}/lib/tomcat-i18n-ru.jar:${j2ee.server.domain}/lib/tomcat-i18n-zh-CN.jar:${j2ee.server.domain}/lib/tomcat-jdbc.jar:${j2ee.server.domain}/lib/tomcat-jni.jar:${j2ee.server.domain}/lib/tomcat-util-scan.jar:${j2ee.server.domain}/lib/tomcat-util.jar:${j2ee.server.domain}/lib/tomcat-websocket.jar:${j2ee.server.domain}/lib/websocket-api.jar
|
||||
j2ee.server.type=Tomcat
|
||||
jar.compress=false
|
||||
javac.classpath=\
|
||||
|
@ -5,10 +5,116 @@
|
||||
*/
|
||||
package bdd;
|
||||
|
||||
import com.test.beans.Pompier;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author clementine.desrucques
|
||||
*/
|
||||
public class PompierMySql {
|
||||
private Connection theConnection;
|
||||
private Pompier unPompier;
|
||||
|
||||
/**
|
||||
* Constructeur
|
||||
*/
|
||||
public PompierMySql() {
|
||||
theConnection = Connexion.getConnect("localhost", //s erveur
|
||||
"sdis29", // base de données
|
||||
"admin",// user
|
||||
"minda"); // mot de passe ClientMysql() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creation du client passé en paramètre dans la table client
|
||||
* Requête non préparée
|
||||
* @param c objet de type Client (sans identifiant)
|
||||
* @return int : id du client créé
|
||||
*/
|
||||
public int create(Pompier p) {
|
||||
int id = -1;
|
||||
try {
|
||||
Statement stmt = theConnection.createStatement();
|
||||
int status = stmt.executeUpdate(
|
||||
"INSERT INTO pompier (idCaserne, nom, prenom, statut, mail, login, mdp, adrNo, adrRue, adrCP, adrVille, grade) "
|
||||
+ "VALUES ('" + p.getIdCaserne() + "', '"
|
||||
+ p.getNom() + "', '"
|
||||
+ p.getPrenom() + "', '"
|
||||
+ p.getStatut() + "', "
|
||||
+ p.getMail() + ", '"
|
||||
+ p.getLogin() + ", '"
|
||||
+ p.getMdp() + ", '"
|
||||
+ p.getAdrNo() + ", '"
|
||||
+ p.getAdrRue() + "', '"
|
||||
+ p.getAdrCP() + "', '"
|
||||
+ p.getAdrVille() + "', '"
|
||||
+ p.getGrade()+ "' );",
|
||||
Statement.RETURN_GENERATED_KEYS);
|
||||
|
||||
// Recherche de l'identifiant du pompier créé
|
||||
if (status > 0) {
|
||||
ResultSet result = stmt.getGeneratedKeys();
|
||||
if (result.first()) {
|
||||
id = result.getInt(1);
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
System.out.println("SQLException : " + ex.getMessage());
|
||||
System.out.println("SQLState : " + ex.getSQLState());
|
||||
System.out.println("Code erreur : " + ex.getErrorCode());
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creation du client passé en paramètre dans la table client
|
||||
* Requête préparée
|
||||
* @param c objet de type Client (sans identifiant)
|
||||
* @return int : id du client créé
|
||||
*/
|
||||
public int createRP(Pompier p) {
|
||||
int id = -1;
|
||||
try {
|
||||
PreparedStatement stmt = null;
|
||||
String sql = "INSERT INTO pompier(idCaserne, nom, prenom, statut, mail, login, mdp, adrNo, adrRue, adrCP, adrVille, grade) "
|
||||
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?);";
|
||||
stmt = theConnection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
||||
stmt.setInt(1, p.getIdCaserne());
|
||||
stmt.setString(2, p.getNom());
|
||||
stmt.setString(3, p.getPrenom());
|
||||
stmt.setInt(4, p.getStatut());
|
||||
stmt.setString(5,p.getMail() );
|
||||
stmt.setString(6,p.getLogin() );
|
||||
stmt.setString(7,p.getMdp() );
|
||||
stmt.setInt(8, p.getAdrNo());
|
||||
stmt.setString(9, p.getAdrRue());
|
||||
stmt.setString(10, p.getAdrCP());
|
||||
stmt.setString(11, p.getAdrVille());
|
||||
stmt.setInt(12, p.getGrade());
|
||||
|
||||
System.out.println("Requête : " + stmt.toString());
|
||||
int status = stmt.executeUpdate();
|
||||
|
||||
|
||||
// Recherche de l'identifiant du client créé
|
||||
if (status > 0) {
|
||||
ResultSet result = stmt.getGeneratedKeys();
|
||||
if (result.first()) {
|
||||
id = result.getInt(1);
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
System.out.println("SQLException : " + ex.getMessage());
|
||||
System.out.println("SQLState : " + ex.getSQLState());
|
||||
System.out.println("Code erreur : " + ex.getErrorCode());
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user