I am developing web application in java using JSP and servlets. I would like to know one thing that is there any way to extract one value from database just like executescalar in .NET.
Ex. select count(*) from userdetails i want to get count without using resultset... is it possible or not....
You can use the following code:
<%@page import="java.sql.*"%> <% Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root"); Statement stmt=con.createStatement(); ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM employee"); rs.next(); int count = rs.getInt(1); out.println("Number of rows: "+count); %>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.