简体   繁体   中英

How to create loop to get each result from the select statement query

I'm just a newbie programmer here and I need your help on how to start working on this..

I'm trying to use/copy this existing method :

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);
}

I'm planning to create another method which is createCancelRecord then I'll add up the query and create a loop from there. Any thoughts on how to code it? Thanks

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM