Your SQLException clearly states that:
You need to point Statement.RETURN_GENERATED_KEYS to Statement.executeUpdate() or Connection.prepareStatement() .
This can be achieved as follows (adding an additional value to the Connection.prepareStatement() method):
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();
Here is Statement.RETURN_GENERATED_KEYS .
Hope this helps!
PS: Useful resource .
@Charlie berg, since you prefer being lazy, I changed line 13 of your code to include 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);
In addition, the Statement class has a java.sql package (make sure you import correctly). :-)