gpt4 book ai didi

java - 需要计数值为0表示显示输出

转载 作者:行者123 更新时间:2023-11-29 14:20:52 25 4
gpt4 key购买 nike

我尝试开发一个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。不显示空白屏幕。所以请帮助我该怎么做。

最佳答案

创建类 RetailerWs 的对象。

RetailerWs  obj =new RetailerWs ();
System.out.println(obj.data());

关于java - 需要计数值为0表示显示输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11776262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com