sql jdbc getgeneratedkeys with mysql returns column "id" not found
        Posted  
        
            by iamrohitbanga
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by iamrohitbanga
        
        
        
        Published on 2010-05-18T05:38:53Z
        Indexed on 
            2010/05/18
            6:30 UTC
        
        
        Read the original article
        Hit count: 273
        
I want to retrieve the most recently updated value in the table using an insert query.
these are the datatypes in my sql table.
int(11) // primary key auto increment, not being assigned by sqlQuery
varchar(30)
timestamp  // has a default value. but i am explicit assigning it using CURRENT_TIMESTAMP
varchar(300)
varchar(300)
varchar(300)
int(11)
varchar(300)
        // java code
        statement.executeUpdate(sqlQuery, Statement.RETURN_GENERATED_KEYS);
        ResultSet rs = statement.getGeneratedKeys();
        System.out.println("here: " + rs.getMetaData().getColumnCount());
        System.out.println("here1: " + rs.getMetaData().getColumnName(1));
        // none of the following 3 works
        System.out.println("id: " + rs.getInt(1));
        System.out.println("id: " + rs.getInt("GENERATED_KEY"));
        System.out.println("id: " + rs.getInt("id"));
for a bit of background see this
© Stack Overflow or respective owner