我認爲這會起作用,但可悲的是它沒有。我得到的錯誤 -返回ArrayList,與get方法結合使用的輸出
在ArrayList類型的方法Add(CustomerInfo)不 適用於參數(字符串)
我的目標是返回Arraylist
,並與訪問獲取方法。當我使用的字符串爲Arraylist
,我不能使用arr.get(I).userID,...... .FirstName ...
類CustomerInfo.java
public class CustomerInfo {
private static Connection conn = null;
private static ResultSet resultSet = null;
public String UserID;
public String FirstName;
public String SecondName;
public ArrayList<CustomerInfo> findCustomer (String userID) throws SQLException {
conn = null;
PreparedStatement pstmt = null;
try {
JDBCConnection jdbcConn = new JDBCConnection();
conn = jdbcConn.openConnection();
ArrayList<CustomerInfo> customerList new ArrayList<CustomerInfo();
String sql = "SELECT USERID FROM TAB0025 WHERE USERID = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, userID);
resultSet = pstmt.executeQuery();
while (resultSet.next()) {
customerList.add(resultSet.getString("USERID"));
customerList.add(resultSet.getString("FIRSTNAME"));
customerList.add(resultSet.getString("SECONDNAME"));
this.UserID = resultSet.getString("USERID");
this.FirstName = resultSet.getString("FIRSTNAME");
this.SecondName resultSet.getString("SECONDNAME");
}
return customerList;
} catch (Exception e) {
throw e;
}
finally {
conn.close();
}
public String getUserID() {
return this.UserID;
}
public String getFirstname() {
return this.FirstName;
}
public String getSecondName() {
return this.SecondName;
}
}
類InputReader.java
// ...
if (CustomerInfo.ExsistUserID(this.UserID)) {
CustomerInfo edit = new CustomerInfo();
ArrayList<CustomerInfo> arr = new ArrayList<CustomerInfo>();
arr = edit.findCustomer(this.UserID);
System.out.println("UserID: "+ arr.get(0).getUserID() + " First Name: "arr.get(0).getFirstName() + " Second Name: " arr.get(0).getSecondName());
}
// ...
你必須要更具體的片約的代碼是給你的錯誤:) – Arkantos 2015-03-13 08:22:01
什麼是「kundenList」這裏的意思。你在哪裏申報。 – Ajit 2015-03-13 08:22:01
@賈尼抱歉,這是一個錯誤,編輯。但這不是問題。 – Panther 2015-03-13 08:23:06