|
-
August 7th, 2011, 06:03 AM
#1
How to use sql LIKE clause in java to retrieve records in database?
Hi,I am having difficulties in retrieving data from database when i am using the LIKE clause in my sql statement.What I actually want is when the user enters a name in the search function,names that are similar to the user input will be retrieve out from the database.But unfortunately,I keep retrieving null.My code looks some thing like this.
public class MemberDetails{
String name;
public MemberDetails(String name){
this.name = name;
}
public ArrayList<String> getMemberSearchResults() {
ArrayList<String> hi = new ArrayList<String>();
ResultSet rs = null;
DBController db = new DBController();
db.setUp("IT2297_Project");
String dbQuery = "SELECT alumni_Name FROM AlumniMembers WHERE alumni_Name
LIKE '" + name + "'";
dbQuery += " Order by alumni_Name";
rs = db.readRequest(dbQuery);
try {
while (rs.next()) {
name = rs.getString("alumni_Name");
hi.add(name);
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(dbQuery);
db.terminate();
return hi;
}
public static void main(String args[]) {
MemberDetails md = new MemberDetails("p");
System.out.println(md.getMemberSearchResults());
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|