View Single Post
Old 17-12-2004, 22:09   #1
andrea
Senior Member
 
L'Avatar di andrea
 
Iscritto dal: Jul 1999
Cittā: Roma
Messaggi: 614
[Java] If in cui entra sempre

Ho questo metodo:

Codice:
public int updateCliente(Connection c, Cliente d) throws SQLException {
  	int id = -1 ;
  	String s = d.getCognome();
    String s1 = d.getNome();
    String idQuery="SELECT * FROM cliente where " + Cliente.COGNOME + "=" + "'" +s +"' AND " +
	Cliente.NOME + "=" + "'" +s1 +"'";
    System.out.println(idQuery);
    Statement st=c.createStatement();
    ResultSet rs=st.executeQuery(idQuery);
    rs.next();
    id=rs.getInt(1);
   	String upQuery = "UPDATE cliente SET ";
    String upQuery2= "WHERE "+Cliente.NOME+"="+"'"+d.getNome()+"' AND " +Cliente.COGNOME+ "="+"'"+ d.getCognome()+"'";
    
    if ( d.getCitta() != " " ) {
    	upQuery = upQuery + Cliente.CITTA + "=" +"'"+d.getCitta()+"'";
    }
    if (d.getEmail()!= " ") {
    	upQuery = upQuery +","+ Cliente.EMAIL+  "=" +"'"+d.getEmail()+"'";
    }
    if (d.getTelefono() != null) {
    	upQuery = upQuery +","+ Cliente.TELEFONO + "=" +"'"+d.getTelefono()+"'";
    }
    if (d.getNazione()!= null) {
    	upQuery = upQuery +","+ Cliente.NAZIONE + "=" +"'"+d.getNazione()+"'";
    }
    if (d.getLingua()!= null) {

    	upQuery = upQuery +","+ Cliente.LINGUA + "=" +"'"+d.getLingua()+"'";
    }
    
    	upQuery= upQuery+upQuery2;
        System.out.println(upQuery);
        st.executeUpdate(upQuery);
       
    return id;
  }
Secondo voi perche' mi esegue sempre tutte le if anche quando i campi di d(che e' un oggetto di tipo cliente con tutti campi stringhe) sono vuoti?Spero che qualcuno possa darmi una mano anche se non credo sia facilissimo.
__________________
...What you know that you time is close at hand, maybe then you'll begin to understand, life down there is just a strange illusion.
andrea č offline   Rispondi citando il messaggio o parte di esso