其中 if (rs.next()==false) {查不到数据 sql执行false rs.next() 如果第一次返回False表示返回为空 如果执行后第一个结果是ResultSet,则返回true,否则返回false。`
public boolean getAllopenid(int tieziid,String openid6) {//public ArrayList getAll(int id)需要找id查找时
//nrbean nr=new nrbean();
//int i=book6.getId();
Connection con = null;
Statement stmt = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
ArrayList hfnr = new ArrayList();
boolean flag = false;
try{
con=sjk.con6();//con由import coo中con6 封装查询
// Class.forName("com.mysql.jdbc.Driver"); 锟斤拷
//con = DriverManager.getConnection("jdbc:mysql://localhost:3306/qqg?useUnicode=true&characterEncoding=utf8","root","456");
pstmt = con.prepareStatement("select * from hf where tieziid ='"+tieziid+"' and hfopenid='"+openid6+"'"); //在这where上面的id
// select 字段1,字段2... from 表1,表2... [where 条件]
//System.out.print(tieziid);
// System.out.print(arg0);
//pstmt.setInt(1,id);
stmt = con.createStatement();
rs = pstmt.executeQuery();
if (rs.next()==false) {// //查不到数据 sql执行false rs.next() 如果第一次返回False表示返回为空 如果执行后第一个结果是ResultSet,则返回true,否则返回false。
//String openid6=rs.getString("hfopenid");
//if((openid6).equals(openid)){//openid){
flag= false;
System.out.print("meiyou");
}
else{
flag=true;
System.out.print("you");
//}
}}
catch(Exception e){System.out.println(e.getMessage());}
return flag;
// return resultBook;
}
下面是调用上面的dao 后 用boolean值 判断有没有查到消息
Boolean a=s4.getallopenid(id,openid);
HashMap li=new HashMap();//null;
//System.out.print(a);
if(a){
int i=0;
li.put("nr",i);
//int i=0;
//String j=JSONArray.fromObject(i).toString();
//JSONArray json = new JSONArray();
// JSONObject jsob=new JSONObject();
// jsob.put("nr", i);
// json.add(jsob);
//response.setContentType("text/html;charset=UTF-8");
// PrintWriter pt=response.getWriter();
// pt=response.getWriter();
// pt.println(jsob);//打印json
System.out.print("cccccccccccccccccccccccc");
}
// request.getRequestDispatcher("../ok.jsp").forward(request, response);}
else{//int i=1;
int i=6;
li.put("nr", i);
//JSONArray json = new JSONArray();
// JSONObject jsob=new JSONObject();
// jsob.put("nr", i);
// json.add(jsob);
//response.setContentType("text/html;charset=UTF-8");
// PrintWriter pt=response.getWriter();
// pt=response.getWriter();
// pt.println(jsob);//打印json
// System.out.print("666666666666666666666666666");
//String j=JSONArray.fromObject(i).toString();
//response.setContentType("text/html;charset=UTF-8");
// PrintWriter pt=response.getWriter();
// pt=response.getWriter();
// pt.println(jsob);}
// request.getRequestDispatcher("regist.jsp").forward(request, response);}
}
// Listli=new ArrayList();// po=null;
// List aa=new List()
// li=d.getAll(la, lo);
// System.out.print(li);
return li;