64 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			64 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
/*
 | 
						|
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 | 
						|
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 | 
						|
 */
 | 
						|
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ès à 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ès à 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;
 | 
						|
    }
 | 
						|
}
 |