java - 从结果集中选择几行 mysql java

标签 java mysql

我在我的java程序中使用了select命令并将其值存储在结果集中。现在,在结果集中循环时,我想使用 select 命令,该命令将选择结果集的前 5 行并插入到其他表中。第二次,它应该选择接下来的 5 行并插入到表中。第三次,依此类推..

Statement s = connection.createStatement();
s.executeQuery("Select * from table1");
ResultSet res = s.getResultSet();
while(res.next()){
 // here i want to select the first 5 lines of the result set and insert in the second       table
}

最佳答案

Statement s = connection.createStatement();
s.executeQuery("Select * from table1");
ResultSet res = s.getResultSet();

while(res.next()){
    // here i want to select the first 5 lines of the result set and insert in the second       table
    while(res.next() && (res.getRow()%5) !=0){
        //select from this table
        //call insert method(what selected)
    }
}

关于java - 从结果集中选择几行 mysql java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13263519/

相关文章:

java - 如何使用 HQL 将 'null' 放入列中?

java - 数据截断 : Incorrect datetime value: '' for column 'date' at row 1

mysql - 如何获取学生详细信息 SQL 查询

java - 是否有扩展 JUnit4 测试类的约定?

java - 我的代码似乎在循环,我不知道为什么

java - 从组合框中选择一个项目(名称)并自动插入正确的外键

mysql - 使用不同数据库且没有公共(public)字段的 MySQL 更新表

php - 如何在 MySQL 列类型 varchar(1000) 中正确写入文本?

java - 将 ImageView 中的图像缩放到高度,保持屏幕边界外的宽高比,并右对齐

java - WebFlux 链接调用多个服务和响应聚合