1

我有一个问题,我无法从 MS SQL Server 数据库中获取我的列表。

这是我的代码:

public List<Location> showLocations(String nmlocation) {
    List<Location> location = new ArrayList<Location>();
    try {
        String sql = "SELECT deskripsi FROM T_Place WHERE ID_Place='%" + nmlocation + "%'";
        PreparedStatement statement = (PreparedStatement) dm.logON().prepareStatement(sql);
        boolean result = statement.execute();
        if (result) {
            ResultSet rs = statement.getResultSet();
            int i = 0;
            while (rs.next()) 
            {
                Location loc = new Location(rs.getString("deskripsi"));
                System.out.println(loc);
                location.add(loc);
                i++;
            }
            rs.close();
        }


     } catch (SQLException sqle) {
      System.out.println("Error on Listing Location Data showLocation Status : " + sqle.getSQLState()
                + " \n Error Message : " + sqle.getMessage()
                + " \n Error State : " + sqle.toString());
    }
    return location;
}

但它显示空结果集。如何解决?提前致谢。

4

0 回答 0