我认为这会起作用,但可悲的是它没有。我得到的错误 -返回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