我想用Java中的jdbc登录。但是我不能在其他类内部或外部try中使用这些值。
我需要使用walletnumberselected和外部其他字符串来尝试捕获。
我该怎么办?
String sql = "SELECT * FROM ACCOUNTS where walletnumber = ? ";
prpstmt = conn.prepareStatement(sql);
prpstmt.setInt(1, input_walletnumber);
ResultSet rs2 = prpstmt.executeQuery();
int walletnumberselected = rs2.getInt("walletnumber"); //Like this
String firstnameselected = rs2.getString("firstname") //Like this
String lastnameselected = rs2.getString("lastname"); //Like this
String passwordselected = rs2.getString("password"); //Like this
也许像这样:
String sql = "SELECT * FROM ACCOUNTS where walletnumber = ? ";
ResultSet rs2 = null;
try {
prpstmt = conn.prepareStatement(sql);
prpstmt.setInt(1, input_walletnumber);
rs2 = prpstmt.executeQuery();
} catch (Exception e) {
// print error...
}
if (rs2 != null) {
int walletnumberselected = rs2.getInt("walletnumber"); //Like this
String firstnameselected = rs2.getString("firstname") //Like this
String lastnameselected = rs2.getString("lastname"); //Like this
String passwordselected = rs2.getString("password"); //Like this
}