sdisM2/src/java/bdd/CaserneMySQL.java
funcha.ahamadi 68bf428f4f Merge origin/master
Conflicts:
	src/java/bdd/PompierMySql.java
	src/java/com/test/servlets/authentifServlet.java
	web/WEB-INF/CreaPompier.jsp
2021-12-13 10:28:40 +01:00

42 lines
1.5 KiB
Java

/*
* bddd/CaserneMySQL.java
*/
package bdd;
import bean.Caserne;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
*
* @author Dominique_2
*/
public class CaserneMySQL {
private final Connection laConnection = Connexion.getConnect("Localhost",
"sdis29",
"adminBDsdis",
"mdpBDsdis");
public Caserne read(int id) {
Caserne laCaserne = null;
try {
PreparedStatement prepStmt = null;
String sql = "SELECT * FROM caserne WHERE id=?";
prepStmt = laConnection.prepareStatement(sql);
prepStmt.setInt(1, id);
ResultSet result = prepStmt.executeQuery();
if (result.next()) {
laCaserne = new Caserne(result.getInt(1), result.getString(2),
result.getString(3), result.getString(4));
}
prepStmt.close();
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
return laCaserne;
}
}