tuo SQLException
afferma chiaramente che:
è necessario specificare Statement.RETURN_GENERATED_KEYS
al Statement.executeUpdate()
o Connection.prepareStatement()
.
Ciò può essere ottenuto come segue (aggiunta di un valore aggiunto a Connection.prepareStatement()
metodo):
String SQL = ""; //whatever my String is
PreparedStatement ps = connection.prepareStatement(SQL, Statement.RETURN_GENERATED_KEYS);
ps.setString(1, "value");
//Other necessary ps.setXXX() methods
//now update
ps.executeUpdate();
ResultSet rs = ps.getGeneratedKeys();
Il Statement.RETURN_GENERATED_KEYS
è chiave qui.
Spero che questo aiuti!
PS: Useful resource.
@Charlie berg, dal momento che si preferisce essere pigro, ho cambiato la linea 13 del codice per includere il Statement.RETURN_GENERATED_KEYS
:
ps = con.prepareStatement("INSERT INTO characters (level, fame, str, dex, luk, `int`, exp, hp, mp, maxhp, maxmp, sp, ap, gm, skincolor, gender, job, hair, face, map, meso, hpMpUsed, spawnpoint, party, buddyCapacity, messengerid, messengerposition, mountlevel, mounttiredness, mountexp, equipslots, useslots, setupslots, etcslots, monsterbookcover, watchedcygnusintro, vanquisherStage, dojopoints, lastDojoStage, finishedDojoTutorial, vanquisherKills, matchcardwins, matchcardlosses, matchcardties, omokwins, omoklosses, omokties, givenRiceCakes, partyquestitems, jailtime, accountid, name, world) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
Inoltre, Statement
classe è del pacchetto di java.sql
(assicuratevi di importare correttamente). :-)
Ciao Charlie, dal momento che i link esterni tendono a decadere e sparire (in particolare pastebin) è meglio includere il codice e le immagini che vuoi mostrare direttamente nella tua domanda. Puoi farlo facendo clic su modifica proprio sopra la casella dei commenti. – James