Hi, I am trying to get autogenerated keys from this table
CREATE TABLE message(
Mid INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY NOT NULL,
Uid INTEGER NOT NULL,
Subject VARCHAR(30) NOT NULL,
Body CLOB NOT NULL,
Creationtime TIMESTAMP DEFAULT CURRENT TIMESTAMP,
FOREIGN KEY(Uid) REFERENCES user(Userid) ON DELETE CASCADE
);
Using IBM DB2

My function Code is as follows
NOTE: conn is a Database type object which handles database operations. And its works PERFECTLY good as i have been using is.

public int addMessage(int uid,String subject, String body)
{
if(isUserIdExists(uid) && isSubjectProper(subject) && body.length()>0)
{
String query = "INSERT INTO message(Uid,Subject,Body) VALUES(?,?,?)";
conn.setPreparedStatement(query);
PreparedStatement statement = conn.getPreparedStatement();
ResultSet key = null;
try {
statement.setInt(1, uid);
statement.setString(2, subject);
statement.setString(3, body);
conn.runQuery();
key = statement.getGeneratedKeys();
key.next();
return key.getInt("Mid");
} catch (SQLException e) {
return -1;
}
}
return -1;
}

If you require what the conn object's function do here is the function
public PreparedStatement getPreparedStatement()
{
return curQueryStatement;
}

public void setPreparedStatement(PreparedStatement inp)
{
curQueryStatement = inp;
}

Now my question:

What am i doing wrong.??????

If i execute addMessage(7,"afada","sadasdadas"); it returns -1

The .next() function in resultset returns a false EVEN thou there is a value inserted into the table.