0
我想從數據庫表supply_location
的ArrayList中獲取位置名稱。但我有一個錯誤:錯誤:java.sql.SQLFeatureNotSupportedException當從數據庫中獲取Arraylist
java.sql.SQLFeatureNotSupportedException
VendorBean:
public class VendorBean {
private String supplyLocation[];
public void setSupplyLocation(String[] supplyLocation) {
this.supplyLocation=supplyLocation;
}
public String[] getSupplyLocation() {
return supplyLocation;
}
}
DAO:
public List<VendorBean> getLocation(String supplyLocation) throws SQLException {
ArrayList<VendorBean> SupplyLocation = new ArrayList<VendorBean>();
try {
String userID = supplyLocation;
con = DBConnection.getConnection();
String query = "SELECT location_name FROM supply_location AS sl\n" +
"LEFT JOIN user_signup AS us \n" +
"ON sl.user_id = us.user_id WHERE us.user_id = ?";
ps = con.prepareStatement(query);
ps.setString(1, userID);
rs = ps.executeQuery();
while(rs.next()) {
VendorBean supplyLoc = new VendorBean();
Array a = rs.getArray("location_name");
String[] location = (String[])a.getArray();
supplyLoc.setSupplyLocation(location);
SupplyLocation.add(supplyLoc);
}
}
finally {
try {
if(rs!=null) {
rs.close();
}
if (ps!=null) {
ps.close();
}
if(con!=null) {
con.close();
}
} catch (SQLException ex) {
//ignore
}
}
return SupplyLocation;
}
我想從數據庫中檢索的LOCATION_NAME格式爲:
1. location_name1
2. location_name2
3. location_name3
4. location_name4
5. location_name5
我有搜索這個問題很多時間,但沒有得到適當的解決方案。請任何人幫助我。
謝謝!
可能出現[SQLFeatureNotSupportedException on getArray]重複(http://stackoverflow.com/questions/11735786/sqlfeaturenotsupportedexception-on-getarray) –