Reputation: 877
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);
I fired this query in mysql and I got the answer is 2. So how can I get and display the result of this query in jsp page?
Upvotes: 0
Views: 2613
Reputation: 681
You can also display result-set and get result in variable like :
<%
while( rs.next()) {
String= rs.getstring(1);
}
%>
Upvotes: 0
Reputation: 441
You can iterate result-set and get result in variable like :
<%
int totalEmployee = 0;
if (rs != null && rs.next()) {
totalEmployee = rs.getInt("totalEmployee");
}
%>
Upvotes: 1