0

I want to query SimpleDB by using the SelectRequest. Here is my code:

String id = String.valueOf(request.getParameter("userid"));
SelectRequest request1 = new SelectRequest(
                                     "select * from Member where Account =" +id,
                                     true
                             );

but it doesn't work.

I have no idea how to solve this problem. Please give me some advice.

mmmmmm
  • 32,227
  • 27
  • 88
  • 117
  • Why are you doing a `String.valueOf()` on a `String`? This makes no sense. This way the `null` literal would become a string with the value `"null"`. – BalusC Jan 06 '12 at 19:24

2 Answers2

1

Firstly, test your sql statement in a console before trying out in the code,

Unless id is an integer (int), you need to add a ['] around it in the sql.

Heres my take:

String id = request.getParameter("userid");
if (id !- null && id.length() > 0) {
    SelectRequest request1 = new SelectRequest(
                                 "select * from Member where Account = '" + id + "'",
                                 true
                         );
} else {
// Do something
}
Araejay
  • 222
  • 1
  • 2
  • 9
0

My first advice is to put the id into single quotes; I am not familiar with SimpleDB or with SelectRequest, but SQL would normally require "select * from X where Y = 'value';" if Y is a character field.

My second advice is to give enough information so that someone has a better chance of telling what is wrong. Do you get an error? Does it display an error and crash? Does it display an error and set fire to the machine? What happens?

arcy
  • 12,845
  • 12
  • 58
  • 103
  • I got an error about invalid query expression.And "id" is defined by using String.valueOf(request.getParameter("userid")).So it cannot use single quotes. – user1134896 Jan 06 '12 at 19:11
  • String id = String.valueOf(request.getParameter("userid")); SelectRequest request1 = new SelectRequest( "select * from Member where Account ='" +id + "'", true ); – arcy Jan 07 '12 at 02:26