在sql db中查找一些项目计数? [英] Find some item count in sql db ?
本文介绍了在sql db中查找一些项目计数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我试着在数据库的名字栏中找到john。但我不知道。能否请你帮忙?谢谢..
Hi everybody, I try to find "john" in "name" column in database.But I did't somehow. Could you please help? Thanks..
String st="SELECT name FROM mytable";
ResultSet rs = stmt.executeQuery(st);
int icount = 0 ;
if (rs.equals("john")) {
while (rs.next()) {
icount++;
}
}
jtext1.setText(String.valueOf(icount));
推荐答案
尝试:
Try:
String st="SELECT name FROM mytable WHERE name LIKE '%john %'";
你可以做到这一切:
You can do it all in one:
String st="SELECT COUNT(*) FROM mytable WHERE name LIKE '%john %'";
String st="SELECT COUNT(*) FROM mytable WHERE name LIKE '%john %'"
ResultSet rs = stmt.executeQuery(st);
int icount = 0;
while (rs.next) {
icount = rs.getInt(1);
}
jtext1.setText(String.valueOf(icount));
上面只有1个记录,其中1个字段是匹配的记录数。
在约翰之后放一个空格以免得到像johnathan等名字,但你可以玩。
There should only be 1 record with 1 field in the above which will be the count of records matching.
Put a space after john so as not to get names like johnathan etc. but you can play around.
这篇关于在sql db中查找一些项目计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文