Hiten Hiten - 1 year ago 46
MySQL Question

how to get mysql query result in jsp page?


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?

Answer Source

You can iterate result-set and get result in variable like :

    int totalEmployee = 0;
    if (rs != null && rs.next()) {
         totalEmployee = rs.getInt("totalEmployee");