|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Jun 2005
Città: CH
Messaggi: 1058
|
probblema java query
Codice:
public boolean esisteUtente(String nomeUtente){
try {
Statement s = this.db.createStatement();
s.executeQuery("SELECT nome FROM utenti");
ResultSet rs = s.getResultSet();
int count = 0;
while (rs.next()) {
String name = rs.getString("nome");
//System.out.println("name:" + name);
if(name.equals(nomeUtente)){
return true;//Il nome esiste già
}else{
return false;//Il nome nn è presente nel db
}
}
rs.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
return false;
}
es lista nomi inseriti Codice:
compile: OK! sei Connesso name:g false D:1 riga inserita g gigi prova3 prova3 prova3 debug: ?_? Coiauu |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Sep 2007
Messaggi: 754
|
Codice:
public boolean esisteUtente(String nomeCliente) {
boolean returnValue=false;
try {
Statement s = this.db.createStatement();
s.executeQuery("SELECT NOME FROM UTENTI WHERE UCASE(NOME)=UCASE(" + nomeCliente + ")");
ResultSet rs = s.getResultSet();
int count = 0;
if (rs.next()) {
returnValue=true;
}
rs.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
return returnValue;
}
__________________
http://www.tevigroup.it/ |
|
|
|
|
|
#3 | |
|
Senior Member
Iscritto dal: Jun 2005
Città: CH
Messaggi: 1058
|
Quote:
nn funziona ! macosa fà quel UCASE?? cmq mi appoggio su mysql .. Ultima modifica di Pro7on : 19-11-2007 alle 10:13. |
|
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Sep 2007
Messaggi: 754
|
Quella è una funzione di mySQL
http://dev.mysql.com/doc/refman/5.0/...function_ucase comunque la mia è solo un attimino piu ottimizzata, la tua se metti il return alla fine funziona comunque. pero mi sembra inutile scorrere tutto il resultset quando puoi fare tutto in un colpo solo. cerca di far funzionare la select che ti ho datao...io nn l'ho porvata, ma la funzione esiste. Prova e fammi sapere.
__________________
http://www.tevigroup.it/ |
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Jun 2005
Città: CH
Messaggi: 1058
|
mm ho provato con query browser e la query funziona, il tuo ragionamento lo capito ma nn riesco a capire xchem mi inserisce i dati ugualmente...
errore Codice:
OK! sei Connesso
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'gigi' in 'where clause'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1027)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3378)
false
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3310)
D:1 riga inserita
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1853)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1976)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2497)
gigi
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2426)
gigi
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1383)
gigi
at progetto.Connessione.esisteUtente(Connessione.java:134)
gigi
at progetto.Connessione.addCliente(Connessione.java:149)
gigi
at progetto.Main.main(Main.java:37)
debug:
BUILD SUCCESSFUL (total time: 4 seconds)
|
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Sep 2007
Messaggi: 754
|
s.executeQuery("SELECT NOME FROM UTENTI WHERE UCASE(NOME)=UCASE('" + nomeCliente + "')");
__________________
http://www.tevigroup.it/ |
|
|
|
|
|
#7 | |
|
Senior Member
Iscritto dal: Jun 2005
Città: CH
Messaggi: 1058
|
Quote:
|
|
|
|
|
|
|
#8 |
|
Senior Member
Iscritto dal: Jun 2005
Città: CH
Messaggi: 1058
|
scherzo scherzo funziona
era un errore di sintasi MIllllleeThxx |
|
|
|
|
|
#9 |
|
Senior Member
Iscritto dal: Sep 2007
Messaggi: 754
|
Adesso ti deve funzionare
Codice:
public boolean esisteUtente(String nomeCliente) {
boolean returnValue=false;
try {
PreparedStatement s = this.db.prepareStatement("SELECT NOME FROM UTENTI WHERE UCASE(NOME)=?");
s.setString(1, nomeCliente.toUpperCase());
ResultSet rs =s.executeQuery();
if (rs.next()) {
returnValue=true;
}
rs.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
return returnValue;
}
__________________
http://www.tevigroup.it/ |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 22:22.



















