permaculture playing cards*
The moose likes Servlets and the fly likes problem with query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem with query" Watch "problem with query" New topic
Author

problem with query

Beksy Kurian
Ranch Hand

Joined: Jul 11, 2001
Posts: 254
I have a query like this:
myRs = myStmt.executeQuery("SELECT id,txt_file FROM table_name WHERE rowid LIKE '" + afileID + "%'");
It works in most cases(AAABBGGAAA) except when the rowid has a value something like this
AAABBGG+AAAA(notice the + sign)
Any way to solve this?
I tried this:
String txtSql = "SELECT id,txt_file FROM table_name WHERE rowid LIKE '" + afileID + "%' ";
myRs = myStmt.executeQuery(txtSql);
It did not work.
and even this:
myRs = myStmt.executeQuery(txtSql.toString());
A fast reply appreciated
Beksy
Beksy Kurian
Ranch Hand

Joined: Jul 11, 2001
Posts: 254
An update! the query is like this
String txtSql = "SELECT id,txt_file FROM table_name WHERE rowid = '" + afileID +"'" ;
I tried to print the query using out.println
It is displaying like this:
SELECT id,txt_file FROM table_name WHERE rowid='AAAFFBB BGG'
The '+' sign is missing and a 'space' is included.
And an error in the browser: Invalid rowid
Please help!
Beksy
Beksy Kurian
Ranch Hand

Joined: Jul 11, 2001
Posts: 254
Looks like problem is that request.getParameter is not bringing the correct rowid. the url i am getting is as below.
/servlet/LoginServlet?pageID=rptdet&fileId=AAAF5WAAHAAAAD+AAF
This is how it is processed... and used it in the above query
String fileID =request.getParameter("fileId");
System.out.println(fileID);
this prints as AAAF5WAAHAAAD AAF
How do we parse it properly so that it won't lose the '+' sign?
Beksy
Beksy Kurian
Ranch Hand

Joined: Jul 11, 2001
Posts: 254
I used URLEncoder and it worked
Beksy
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: problem with query
 
Similar Threads
Difference between rowid and rownum in sql query??
SQL Server limiting result set
database
sql query to check for a table with an expression
How to delete duplicate rows