// 查询用户
public static void searchUserBeans(XMPPConnection conn, String userName) throws XMPPException{
UserSearchManager usm = new UserSearchManager(conn);
org.jivesoftware.smackx.Form searchform = usm
.getSearchForm("search.192.168.1.66");//注意:search表单默认都是search.服务器地址
org.jivesoftware.smackx.Form answerForm = searchform
.createAnswerForm();
answerForm.setAnswer("Username", true);
answerForm.setAnswer("search", userName);
ReportedData data = usm.getSearchResults(answerForm,
"search.192.168.1.66");
Iterator<Row> it = data.getRows();
Row row = null;
while (it.hasNext()) {
row = it.next();
String uname = row.getValues("Username").next().toString();
String Email = row.getValues("Email").next().toString();
String Name = row.getValues("Name").toString();
row.toString();
System.out.println("----------uname---------" + uname);
System.out.println("----------Email---------" + Email);
System.out.println("----------Name---------" + Name);
}
}
如果自己嫁接的数据库表搜索用户的话需要自己写个类继承IQ,替换UserSearch类,最后别忘了在配置信息里面将
// User Search
pm.addIQProvider("query", "jabber:iq:search", new UserSearch.Provider());替换成自己的类