12.07.2015 Views

Università degli Studi di Napoli Federico II Facoltà di ... - Scope

Università degli Studi di Napoli Federico II Facoltà di ... - Scope

Università degli Studi di Napoli Federico II Facoltà di ... - Scope

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

private Connection db = null; // La connessione con il Databasepublic Database() {this.nomeDB = "studentivomsdb";this.nomeUtente = "root";this.pwdUtente = "*********";errore = "";}public String getErrore(){return this.errore;}// Apre la connessione con il Databasepublic void connetti() {try {if(db==null){// Carico il driver JDBC per la connessione con il database MySQLClass.forName("com.mysql.jdbc.Driver");// La connessione necessita della passworddb = DriverManager.getConnection("jdbc:mysql://localhost:3306/" + nomeDB + "?user="+ nomeUtente +"&password=" + pwdUtente);// La connessione è avvenuta con successo}}catch (Exception e) { errore = e.getMessage(); }}public void closeConnection(){if(db!=null){try {db.close();db = null;} catch (SQLException ex) {ex.printStackTrace();}}}//querypublic ResultSet getCertRobot() throws SQLException{ResultSet result = null;this.connetti();Statement stmt = db.createStatement();result = stmt.executeQuery("select userid,cn from usr where cn LIKE '%Robot%'");return result;}public boolean getResponseEmail(String email, long certificatoRobot){this.connetti();ResultSet result = null;int count = 0;int countM = 0;long rid=0;//trasformo la mail in "role" perchè mi servirà dopoString emailMo<strong>di</strong>f= email.replaceAll("@", "_at_");try {Statement stmt = db.createStatement();result = stmt.executeQuery("select count(*) mail from request_pen<strong>di</strong>ng where maillike '"+ email+"'");if(result.next()){count = result.getInt(1);}stmt.close();//cancella le successive righeif (count == 0) {//vuol <strong>di</strong>re che non c'è una richiesta pendente con la stessa mail//e quin<strong>di</strong> controllo se questo role è già associato al certifRobot//passato al metodo (che sarebbe il certif scelto dall'utente)!!!stmt = db.createStatement();Luca Gerardo 566/2636 Pagina 97 <strong>di</strong> 113

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!