public C[] getC() throws SQLException, ClassNotFoundException {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:Mydb";
String user = "user1";
String password = "password";
Connection con = DriverManager.getConnection(url,user,password);
Statement smt= con.createStatement();
String query = "Select ssn, cname from customer";
ResultSet rs = smt.executeQuery(query);
C [] c = new C[getNumberOfCustomers()];
while (rs.next()){
String ssn = rs.getString("ssn");
String customer_name = rs.getString("cname");
}
return custarray;
}
这是C的代码:
public class C {
private String name;
private String SocialSecurityNumber;
public C(String name, String SocialSecurityNumber) {
this.name = name;
this.SocialSecurityNumber = SocialSecurityNumber;
}
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getSocialSecurityNumber() { return SocialSecurityNumber; }
public void setSsn(String SocialSecurityNumber ) {
this.SocialSecurityNumber = SocialSecurityNumber;
}
}
在这里,我在将 ssn 和 customer_name 传递给C[]
数组时遇到问题