Java 如何从resultset中获取值并将其插入到另一个表中
我想获取rs.getInt1值并将其插入param表中Java 如何从resultset中获取值并将其插入到另一个表中,java,sql,Java,Sql,我想获取rs.getInt1值并将其插入param表中 public void () { result rs; int id = 0; final String queryStr = "select MAX(id) from IDEAA"; try { connect.connect(); rs = connection.execute
public void () {
result rs;
int id = 0;
final String queryStr = "select MAX(id) from IDEAA";
try {
connect.connect();
rs = connection.executeQuery(queryStr);
while (rs.next()) {
id = rs.getInt(1); // I need to get the value , Here i get the correct value
}
final String querySt = "insert into param(id,param_id,value) values "
+ "(" + id + "," + TEST + ",'" + "TEST" + "'" + ")" // But when it comes here it the becomes zero.
}
有人能推荐我吗?如果您能在代码中提供更多信息,rs变量是什么类型的,如果第三方lib 我仍然不明白为什么会有一个while循环,因为max id总是返回一个最高的值 if也值得一试,看看是否可以将rs设置为开始。卢比优先 然后尝试检索该值
public void () {
result rs;
int id = 0;
final String queryStr = "select MAX(id) from IDEAA";
try {
connect.connect();
rs = connection.executeQuery(queryStr);
rs.first();
id = rs.getInt(1);
final String querySt = "insert into param(id,param_id,value) values "
+ "(" + id + "," + TEST + ",'" + "TEST" + "'" + ")" // But when it comes here it the becomes zero.
}
格廷
int getInt列索引
抛出SQLException
在Java编程语言中,以int形式检索此ResultSet对象当前行中指定列的值。
参数:
columnIndex-第一列是1,第二列是2。。。
返回:
列值;如果该值为SQL NULL,则返回的值为0
抛出:
SQLException-如果columnIndex无效;如果发生数据库访问错误或在关闭的结果集上调用此方法是否尝试调试代码?@pals代码看起来不错,请调试代码,或放置一些日志语句或syso语句。