为什么不报错,但是就是查询不出值
public class servletList extends HttpServlet {
private static final String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //数据库驱动
//连接数据库的URL地址
private static final String url="jdbc:sqlserver://localhost:1433;DatabaseName=message";
private static final String username="sa";//数据库的用户名
private static final String password="123";//数据库的密码
private static Connection conn=null;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try {
Class.forName(driver);
conn = DriverManager.getConnection(url, username, password);
String sql = "select id,command,description,contents from messageTable";
PreparedStatement statement = conn.prepareStatement(sql);
ResultSet rs = statement.executeQuery();
List<messageItems> messageList = new ArrayList<messageItems>();
while(rs.next())
{
messageItems items = new messageItems();
messageList.add(items);
items.setId(rs.getInt("id"));
items.setCommand(rs.getString("command"));
items.setDescription(rs.getString("description"));
items.setContents(rs.getString("contents"));
}
req.setAttribute("messageList", messageList);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
req.getRequestDispatcher("/WEB-INF/jsp/back/list.jsp").forward(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
this.doGet(req, resp);
}
}