gpt4 book ai didi

java - 如何创建循环以获取 select 语句查询的每个结果

转载 作者:太空宇宙 更新时间:2023-11-04 13:39:51 25 4
gpt4 key购买 nike

我只是一个新手程序员,我需要你的帮助来了解如何开始工作......

我正在尝试使用/复制这个现有方法:

private String createDeleteRecord(int rowNum, String[] record) {
StringBuffer sb = new StringBuffer(rowNum + "~D~N~");

for (int i = 0; i < (intNoOfStaticCols - 1); i++) {
sb.append(record[i].trim() + "~");
}

return sb.substring(0, sb.length() - 1);
}

我计划创建另一个方法,即 createCancelRecord,然后我将添加查询并从那里创建一个循环。关于如何编码有什么想法吗?谢谢

最佳答案

Connection con=DriverManager.getConnection("connection url","user_name","password");//create connection

Statement stmt=con.createStatement();//create a statement

ResultSet rs=stmt.executeQuery("select * from table_name"); //this stores the result of select statement into ResultSet object

while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3)); ////this is the loop to print each row

关于java - 如何创建循环以获取 select 语句查询的每个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31338409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com