select count(*).. 在java中执行这段sql语句,要是查询结果不为0则停止执行,并报错。java程序该怎么写?
selectcount(*)frombtoroomwhereAL_IDisnullorlen(al_id)=0,在java中执行这段sql语句,要是查询结果不为0则停止执...
select count(*) from btoroom where AL_ID is null or len(al_id) = 0
,在java中执行这段sql语句,要是查询结果不为0则停止执行,并报错。java程序该怎么写?
数据库“local/study”,sa,密码0000,用jtds的话怎么写?其他方法呢?完整点啊~~~~ 展开
,在java中执行这段sql语句,要是查询结果不为0则停止执行,并报错。java程序该怎么写?
数据库“local/study”,sa,密码0000,用jtds的话怎么写?其他方法呢?完整点啊~~~~ 展开
展开全部
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();
}
}
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();
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询