Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(url, "root", "");
// assuming your SQL Server's username is "username" // and password is "password"
Statement st = conn.createStatement();
String sql = "Select count(role) as totalEmployee from login where role = 'employee'";
ResultSet rs = st.executeQuery(sql);
我在 mysql 中触发了这个查询,得到的答案是 2。 那么如何在jsp页面中获取并显示该查询的结果呢?
最佳答案
您可以迭代结果集并在变量中获取结果,例如:
<%
int totalEmployee = 0;
if (rs != null && rs.next()) {
totalEmployee = rs.getInt("totalEmployee");
}
%>
关于java - 如何在jsp页面中获取mysql查询结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39122273/