我尝试开发一个 java 应用程序。这里正在从 mysql 数据库获取信息。我的代码是:
public class RetailerWs {
public int data(){
int count=0;
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 MONTH(date) = MONTH(CURDATE()) AND YEAR(date) = YEAR(CURDATE())");
ResultSet result = statement.executeQuery();
while(result.next()) {
// Do something with the row returned.
count++; //if the first col is a count.
}
}
catch(Exception exc){
System.out.println(exc.getMessage());
}
return count;
}
}
另一类是:
public class Demo {
public static void main(String[] args){
RetailerWs obj = new RetailerWs();
System.out.println(obj.data());
}
}
在这里我必须检查查询并显示计数值是否成功。但我怀疑查询匹配项为零表示输出显示空白。但我希望它是显示 0.不显示空白屏幕..所以请帮忙我该怎么办。