i have try to develop count the value is displayed on my apache-tomcat console window.
here am using following code:
public class RetailerWs {
public int data(){
int count=0;
count++;
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pro","root","");
PreparedStatement statement = con.prepareStatement("select * from orders where status='Q' AND date=CURDATE()");
ResultSet result = statement.executeQuery();
}
catch(Exception exc){
System.out.println(exc.getMessage());
}
return count;
}
}
my another class is:
public class Demo {
public static void main(String[] args){
RetailerWs obj = new RetailerWs();
System.out.println(obj.data());
}
}
In my database have 2 values are matched above query.but the output is displayed is always 1.why dis error is occurred here.please help me what loop condition is am used here.give me some solutions.
You aren’t actually looking at the results of your query.
countis 1 because of thecount++earlier in the code.You need something like: