Java JDBC,MySQL:从PreparedStatement返回行数据

Java JDBC,MySQL:从PreparedStatement返回行数据,java,mysql,jdbc,prepared-statement,Java,Mysql,Jdbc,Prepared Statement,我正在使用以下设置: public MySQLProcessWriter(Connection con) throws SQLException { String returnNames[] = {"processId","length","vertices"}; addresser = con.prepareStatement("INSERT INTO addressbook (length, vertices, activity) VALUES (?, ?, ?)", returnNa

我正在使用以下设置:

public MySQLProcessWriter(Connection con) throws SQLException { 
 String returnNames[] = {"processId","length","vertices"};
 addresser = con.prepareStatement("INSERT INTO addressbook (length, vertices, activity) VALUES (?, ?, ?)", returnNames);
}
processId
对应于addressbook表中的一个自动递增列。这样的想法是:我重复插入,我得到一些插入的内容+自动生成的processId。然而,当我尝试
address.getGeneratedKeys().getInt(“processId”);时,我得到了一个“column not found”SQLException在执行准备好的语句之后(在适当的值设置之后)。代码是

addresser.setInt(1, length);
addresser.setInt(2, vertices);
addresser.setDouble(3, activity);
addresser.executeUpdate();
int processId = addresser.getGeneratedKeys().getInt("processId");

在更新长度、顶点和活动的循环内。那么…什么给了你?我是否误解了prepareStatement(sqlstring,string[])方法的作用?

在调用
getInt()
之前,您必须在
ResultSet
上调用
next()
方法


我认为需要对返回的结果集调用next()

ResultSet keys = addresser.getGeneratedKeys();
int processId = -1;
if (keys.next())
{
  processId = keys.getInt("processId");
}

好。。我想我不是第一个。。。看来我们都是对的。
ResultSet keys = addresser.getGeneratedKeys();
int processId = -1;
if (keys.next())
{
  processId = keys.getInt("processId");
}