You are right on. Why did I not see that? Thanks. Viet Pham
On Sat, Mar 21, 2009 at 11:21 AM, Vitali Lovich <[email protected]> wrote: > Do not do executeUpdate(sql). I'm pretty sure that's the problem. Just do > an executeUpdate(). Hope you can see why. > > Does that fix the problem? > > > On Sat, Mar 21, 2009 at 11:01 AM, Pham Tran Quoc Viet < > [email protected]> wrote: > >> Hi All,I my GWT-based application, the INSERT statement inserts a record >> into the database. It, however, throws the error in red below when hitting >> the UPDATE statement (in bold and at the bottom). Please help. >> >> com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an >> error in your SQL syntax; check the manual that corresponds to your MySQL >> server version for the right syntax to use near '? WHERE UserId = ?' at line >> 1 >> >> connection = cadaoDb.getConnection(); >> connection.setAutoCommit(false); >> sql = "INSERT INTO User (First, Middle, Last, ID) " + "VALUES (?, ?, ?, >> ?)"; >> ps = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); >> ps.setString(1, mem.getFirst()); >> ps.setString(2, mem.getMiddle()); >> ps.setString(3, mem.getLast()); >> ps.setString(4, ""); >> ps.executeUpdate(); >> int userId = cadaoDb.getGeneratedId(ps.getGeneratedKeys()); >> >> id = generateId(userId); >> sql = "UPDATE User SET ID = ? WHERE UserId = ?"; >> ps = connection.prepareStatement(sql); >> ps.setString(1, id);//I checked, id = non-empty string >> ps.setInt(2, userId);//I checked, userId = 1 >> ps.executeUpdate(sql); >> > >> It, however, works when I replace question marks in the update sql >> statement with real value like this: >> >> id = generateId(userId); >> sql = "UPDATE User SET ID = 'abc' WHERE UserId = 1"; >> ps = connection.prepareStatement(sql); >> ps.executeUpdate(sql); >> > >> >> > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~----------~----~----~----~------~----~------~--~---
