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 need cast 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

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -