aspose file tools*
The moose likes JDBC and the fly likes wildcard search using jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "wildcard search using jdbc" Watch "wildcard search using jdbc" New topic
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: 1772
    
  14

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.


No more Blub for me, thank you, Vicar.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30753
    
156

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: 1772
    
  14

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: wildcard search using jdbc