java如何从dao函数返回整数?
在一个servlet程序中,我创建了一个包含函数的DAO类,我希望返回通过执行Oracle查询生成的特定值。我试过这样的方法:
public int timeofdayafternoonthsmon(Getset g) throws ClassNotFoundException, SQLException {
// TODO Auto-generated method stub
Connection con=Dbconnection.getConnection();
String userid=g.getuserid();
PreparedStatement pstmt=con.prepareStatement("select count(timeofday) from mealdb where timeofday=? and userid=?");
pstmt.setString(1,"Afternoon");
pstmt.setString(2,userid);
int no=pstmt.executeUpdate();
System.out.println(""+no);
return no;
}
但问题是它(我猜)会以1作为成功。但是我希望它返回执行这个查询的结果
# 1 楼答案