Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wildcard search using jdbc

 
krishna moorthyv
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2407
32
Linux Oracle Postgres Database Python Scala
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
krishna moorthyv
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2407
32
Linux Oracle Postgres Database Python Scala
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic