-2

The error states that the index of the illegal character is 6 but the 6th character is the space after SELECT

    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://sql3.freemysqlhosting.net:3306/";

static final String USER = "****";
static final String PASS = "****";

public JSONArray getLocation(ArrayList postParameters)
{
    Connection conn = null;
    HttpEntity httpEntity = null;
    try{

        Class.forName(JDBC_DRIVER);

        System.out.println("Connecting ");
        conn = DriverManager.getConnection(DB_URL, USER, PASS);
        System.out.println("Connection successful.");

        String sql = "SELECT * FROM locations WHERE locTag LIKE '%"+postParameters+"%'";

        DefaultHttpClient httpClient = new DefaultHttpClient();

        HttpPost httpPost = new HttpPost(sql);
        httpPost.setEntity(new UrlEncodedFormEntity(postParameters,"UTF-8"));
        HttpResponse httpResponse = httpClient.execute(httpPost);
        httpEntity = httpResponse.getEntity();

i am then getting

java.lang.IllegalArgumentException: Illegal character in path at index 6: select * FROM locations WHERE locTag = '%[locTag=fast]%'

I have also tried encoding but no luck.

sr90
  • 67
  • 1
  • 7

1 Answers1

0

You are trying to execute an SQL query as a HTTP request. That makes no sense at all. The HttpPost constructor expects an URI, a select statement is not a URI.

You either need to use JDBC to execute the query, or you need to GET or POST a URI. I can't tell from your code what you are actually trying to do though.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197