0

I am developing a java app, and I use resultset. I write this query, it works and I get the results

SELECT * 
FROM BD 
WHERE 
    CAST(parent_id AS integer) = " + (Integer.parseInt(arrHeading[0])) + " 
    AND CAST(section AS double precision) = " + Double.parseDouble(arrHeading[1]) + "";

arrHeading is type string, but when I write the query below it does not return any results. cas is type character varying(12). I am having trouble because it's a character, and I dont know why I am not getting any result. I tried with the quotes but still does not work. Any ideas?

SELECT * 
FROM BD 
WHERE 
    CAST(parent_id AS integer) = " + (Integer.parseInt(arrHeading[0])) + " 
    AND CAST(section AS double precision) = " + Double.parseDouble(arrHeading[1]) + "
    AND cas = '" + arrHeading[2] + "'";

1 Answer 1

3

I will suggest to first replace arrHeading[2] with the actual value in the query, i.e. hardcode cas=" 'your valiue' " and see if the query returns any result

Sign up to request clarification or add additional context in comments.

4 Comments

I replace with SELECT * FROM BD WHERE CAST(parent_id AS integer)=" + (Integer.parseInt(arrHeading[0])) + " AND CAST(section AS double precision)=" + Double.parseDouble(arrHeading[1])+ "AND cas='" + "B1"+"'"; and I get results
@bentham - and if you print your query string?
I get SELECT * FROM BD WHERE CAST(parent_id AS integer)=19 AND CAST(section AS double precision)=1665.0 AND cas='B1 '
it seems arrHeadin[2] have an extra white space, use arrHeading[2].trim()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.