大家好,我想知道类似这样的一个servicebean如何把报错的message返回到页面?
代码片段如下:
private static final String ERROR = "数据库错误:";
private static final String RETRIEVE_STMT =
"SELECT * FROM Alliance WHERE lyear=? AND season=?";
......
public List<Alliance> retrieveAll() throws AllianceException{
Connection connection = null;
PreparedStatement stmt = null;
ResultSet results = null;
try {
connection = ds.getConnection();
stmt = connection.prepareStatement(RETRIEVE_ALL_STMT);
results = stmt.executeQuery();
List<Alliance> AllianceList = new LinkedList<Alliance>();
while (results.next()) {
League league = new League(results.getInt("lid"),
results.getInt("lyear"),
results.getString("season"),
results.getString("title"));
allianceList.add(alliance);
}
return allianceList;
} catch (SQLException e) {
throw new AllianceException(ERROR + e.getMessage());
} finally {
if (results != null) {
try { results.close(); } catch (SQLException se) { }
}
if (stmt != null) {
try { stmt.close(); } catch (SQLException se) { }
}
if (connection != null) {
try { connection.close(); } catch (SQLException e) { }
}
}
}
如果用ajax传后台数据到前端页面,如何传递这些报错消息?请教。谢谢。