java - How do you convert this SQL query from String to Int? -
java - How do you convert this SQL query from String to Int? -
how convert sql query string int ?
string sql = "delete demo.question " + "where cast (question_id = '"+question+"' ,int(10))";
answering question: trying perform cast
operation on boolean value, don't think want (and it's irrelevant anyway).
so, think trying this:
sql = "delete demo.question " + "where question_id = cast('" + question + "', int)"
some comments on this:
your question variable can parsed integer value in code before passing query... remove needcast
function. what if question
variable holds value "abc"
? consider scenario. your query quite vulnerable sql injection attacs. consider using prepared statements. update
since using java, , reinforcing 3rd observation, should take the java tutorial on topic (and this).
i insist, instead of passing string , casting in query, parse in java code integer , free of problem.
java derby
Comments
Post a Comment