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页面中获取并显示该查询的结果呢?
答案 0 :(得分:1)
您可以迭代结果集并将结果输入变量,如:
<%
int totalEmployee = 0;
if (rs != null && rs.next()) {
totalEmployee = rs.getInt("totalEmployee");
}
%>
答案 1 :(得分:0)
您还可以显示结果集并将结果输入变量,如:
#!/path/to/python