1
String doc = String.valueOf(po.get_Value("DocumentNo"));

I used above code but still it's taking the integer value in the query. Below I mentioned the query where I want the String value.

String sql = "update C_partial SET IsExported = 'Y' where documentno ="+doc;
4
  • ehm ... what exactly do you mean? no matter what type doc is at that point (it is a String, btw), through the concatenation, it would become part of a String. So what do you get as result that is not correct? Commented Nov 10, 2015 at 12:38
  • 1
    What do you mean with Integer value and String value? do you actually want the query to just end with "...documentno = ' +doc + "'";? Commented Nov 10, 2015 at 12:38
  • 1
    Please see JDBC PreparedStatement with particular reference to parameter placeholders, and also see SQL Injection. Commented Nov 10, 2015 at 12:41
  • the data type of document no column is integer, same i executed in sql developer then i have put document no in ' '(Single quote) Commented Nov 10, 2015 at 12:42

3 Answers 3

4

Use PreparedStatement

String sql = "update C_partial SET IsExported = 'Y' where documentno =?";

PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, doc);

It is just safer and cleaner

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

Comments

0

You need to wrap with apostrophe characters

String sql = "update C_partial SET IsExported = 'Y' where documentno = '"+doc+"'";

Comments

0

You can use

String.valueof();

like this and add ' to your query

String sql = "update C_partial SET IsExported = 'Y' where documentno = '"+String.valueOf(doc) +"'";

1 Comment

wouldn't change anything. doc already is a String, he already applied String.valueOf(...), and even if not, the concatenation itself would render it as a part of the String

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.