public void sqlTest throws SQLException{
Connection con=null;
Statement st=null;
ResultSet rs=null;
int a=0;
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
con = DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/study","sa","0000");
st = con.createStatement();
String sqlStr="select count(*) from btoroom where AL_ID is null or len(al_id) = 0 ";
rs = st.executeQuery(sqlStr);
if(rs.next()){
a = rs.getInt(0);
if(a==0){
throw new Exception("记录数为0!")
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}finally{
con.close();
st.close();
rs.close();
}
}
查询结果不为0则停止执行,是让后面的代码不再执行吗?还有,报错,需要报什么错误?NullPointerException?还是其他错误?