jsp判断用select读取的数据是否有0

<%
//加载MySQL驱动
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/new_schema"; //数据库名
String username = "root"; //数据库用户名
String password = "1234567890"; //数据库用户密码
Connection con = DriverManager.getConnection(url, username, password); //连接状态
// 判断数据库是否连接成功
if (con != null){
System.out.println("数据库连接成功");
out.print("数据库连接成功!");
}else {
System.out.println("数据库连接失败");
}
String sql ="SELECT * FROM tb_stu where id in (SELECT stu_id FROM tb_apply where tea_id=1 and status=5)"; //查询语句
Statement stmt = null;
ResultSet rs = null;
stmt = con.createStatement();
rs = stmt.executeQuery(sql);

int lastRow=rs.getRow();
out.print(lastRow);
%>
posted @ 2023-02-07 13:43  祥瑞哈哈哈  阅读(32)  评论(0)    收藏  举报