错误:java.sql.SQLFeatureNotSupportedException从数据库

时间:2016-05-06 12:37:29

标签: java arraylist

我想从数据库表supply_location获取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

我已经多次搜索此问题,但没有得到正确的解决方案。请有人帮助我。

谢谢!

1 个答案:

答案 0 :(得分:0)

这看起来像您的数据库不支持ARRAY列类型。请参阅问题SQLFeatureNotSupportedException on getArray