Observation Fini de l'affichage à l'insertion SQL

This commit is contained in:
2025-03-13 09:51:28 +01:00
parent 4813c5d4af
commit 85c17dbe6f
4 changed files with 212 additions and 8 deletions

View File

@@ -4,10 +4,60 @@
*/
package acces_aux_donnes;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
*
* @author emile.lalorcey
*/
public class observationSQL {
private Connection connexionTest;
private Statement stmt = null;
private ResultSet result = null;
public observationSQL() {
connexionTest = connexionSQL.getConnect("10.121.38.75","bdgsb","adminGSB","mdpGSB");
}
public int compterLignes(){
int nbLignes = 0;
try {
stmt = connexionTest.createStatement();
// Acc<63>s <20> la table
result = stmt.executeQuery("SELECT COUNT(idObservation) From OBSERVATION");
if (result.next()) {
nbLignes = Integer.parseInt(result.getString(1));
}
result.close();
stmt.close();
} catch (SQLException ex) {
System.out.println("SQLException : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
return nbLignes;
}
public int ajouterObservation(String idMedoc, int idPraticien, String observation){
int passer = 1000;
int nbLignes = this.compterLignes();
try {
stmt = connexionTest.createStatement();
// Acc<63>s <20> la table
passer = stmt.executeUpdate("INSERT INTO OBSERVATION(idObservation, idMedoc, idPraticien, observation) "
+ "VALUES ("+(nbLignes+1)+",'"+idMedoc+"',"+idPraticien+",\""+observation+"\");");
result.close();
stmt.close();
}catch (SQLException ex) {
System.out.println("SQLException : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
return passer;
}
}