wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 1610
    
  13

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30076
    
149

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: 1610
    
  13

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
 
Similar Threads
Java won't send SQL query
Connect MySql to Android
error while using sql update statement
ClassNotFoundException with ResourceBundle
How to use Usebean Tag and setProperty and getProperty