questo è un metodo per fare un insert o un update in una tabella(access)non mi da errore però non mi effettua ne' l'update ne' insert?
perche?
codice:
public static Utente inserimentoUtente (String creazione,String username,String password,int idProgramma,String ragioneSociale,boolean admin, String eMail)throws ErroreAccessoDatiException,SQLException{
if(dataSource == null){
throw new IllegalStateException("LoginDBManager non ha ancora a disposizione un DataSource valido");
}
String tmp=creazione;
String sqlQuery=null;
if (tmp.equals("creazione")){
sqlQuery = ("insert into utenti values(?,?,?,?,?,?)");
}
else{
sqlQuery = ("update utenti set ragioneSociale=? where username like ?");
}
Connection connection = null;
PreparedStatement pStat = null;
ResultSet rSet = null;
try{
connection = dataSource.getConnection();
pStat = connection.prepareStatement(sqlQuery);
if (tmp.equals("creazione")){
pStat.setString(1,username);
pStat.setBytes(2,SecurityUtils.getHash(password));
pStat.setString(3,eMail);
pStat.setString(4,ragioneSociale);
String amministratore=null;
if (admin){
amministratore=("S");
}
else{
amministratore=("N");
}
pStat.setString(5, amministratore);
int idPragramma=idProgramma;
pStat.setInt(6, idProgramma);
}
else{
pStat.setString(1,ragioneSociale);
pStat.setString(2,username);
}
pStat.execute();
System.out.println("update " + ragioneSociale);
Utente utenteNuovo = UtentiDBManager.trovaUtente(username);
System.out.println("punto3 " + utenteNuovo.getUsername());
if (utenteNuovo!=null){
System.out.println("dentro if" );
return utenteNuovo;
}
else {
return null;
}
}
catch(SQLException errore){
throw new SQLException(errore.getMessage(),String.valueOf(er rore.getErrorCode()));
}
catch(ErroreAccessoDatiException errore){
throw new ErroreAccessoDatiException(errore.getMessage(),Str ing.valueOf(errore.getErrorCode()));
}
finally{
try{rSet.close();}catch(Exception e){}
try{pStat.close();}catch(Exception e){}
try{connection.close();}catch(Exception e){}
}
}
}
aiuto sono due giorni che non riesco a risolvere nulla!!!
![]()
![]()