Author
wildcard search using jdbc
krishna moorthyv
Greenhorn
Joined: Dec 13, 2012
Posts: 7
i need to extract similarty keyword in my mysql database, so i am using wildcard search ,i try to print but it always print hash code value.... please any one help me
i'm using mysql 5.1 my schema name is search and my table name is totall
chris webster
Bartender
Joined: Mar 01, 2009
Posts: 1125
posted Dec 14, 2012 06:14:35
1
Use a PreparedStatement with bind variables instead of a dumb string for your SQL, then you can supply a wildcard value as the search-value in the bind variable . Also, you would normally loop through the rows returned in your ResultSet to extract the selected values. Here's an example .
ex-Oracle bloke
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26489
Welcome to CodeRanch! I edited your post to add code tags to make it easier to read.
The problem is this:
rs is a Java object. To output the results, you need to loop through them as:
[Blog ] [JavaRanch FAQ ] [How To Ask Questions The Smart Way ] [Book Promos ]
Blogging on Certs: SCEA Part 1 , Part 2 & 3 , Core Spring 3 , OCAJP , OCPJP beta , TOGAF part 1 and part 2
krishna moorthyv
Greenhorn
Joined: Dec 13, 2012
Posts: 7
thanks to javaRanch i got an output.My mistake is i directly print the result set value instead of using
while(rs.next)
{
System.out.println(rs.getstring("record"));
}
chris webster
Bartender
Joined: Mar 01, 2009
Posts: 1125
posted Dec 14, 2012 09:17:53
1
krish javabeginner wrote: thanks to javaRanch i got an output.
Well done! Now go and read about SQL injection and then try writing your program using a PreparedStatement instead to prevent this.
subject: wildcard search using jdbc