你好朋友我有这个从数据库中获取值的类:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.mail.Message;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class EmailAlerts {
public static void main(String[] args) {
SMTPAuthenticator sm = new SMTPAuthenticator();//new class
Connection conn = null;
String AtmName = "";
String AtmBal = "";
String atmsend = "";
String[] bals = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.80:1521:dev9i", "BI", "bi");
Statement st1 = conn.createStatement();
String atms = "select CLR_BAL_AMT, FORACID, ACCT_NAME from gam "
+ "where BACID = 'ATM' and CLR_BAL_AMT < 100000";
ResultSet rs1 = st1.executeQuery(atms);
while (rs1.next()) {
AtmName = rs1.getString("ACCT_NAME");
AtmBal = rs1.getString("CLR_BAL_AMT");
bals = AtmBal.split("\n");
for (int j = 0; j < bals.length; j++) {
atmsend = AtmName + "-" + AtmBal;
//System.out.println(atmsend);
}
}
System.out.println(atmsend);
}catch(Exception ad){
System.out.println(ad);
}
}
}
当我尝试在 While 循环外打印出变量“atmsend”时,它只给出数据库中的最后一个值,但在 for 循环内,数据库中的所有记录都在那里。如何在 While 循环之外拥有数据库中的所有记录?