Click here to Skip to main content
15,903,540 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everybody, I try to find "john" in "name" column in database.But I did't somehow. Could you please help? Thanks..

Java
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));
Posted
Updated 3-Jan-16 0:09am
v2

1 solution

Try:
C#
String st="SELECT name FROM mytable WHERE name LIKE '%john %'";

You can do it all in one:
C#
String st="SELECT COUNT(*) FROM mytable WHERE name LIKE '%john %'";


C#
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));


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.
 
Share this answer
 
v6
Comments
bugsoul 3-Jan-16 7:11am    
Thanks Michael, but sorry I am a begginer;

well, how can I get that result. I mean how can I ".settext" to jtext1.

thanks again..
ridoy 3-Jan-16 8:05am    
Don't get your point. do you try the query @Michael_Davies posted?
Michael_Davies 3-Jan-16 9:07am    
Updated my answer.
ridoy 3-Jan-16 12:49pm    
a 5 from me!
bugsoul 3-Jan-16 9:12am    
Thank you so much...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900