Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prepared statement. Can I miss out parameter?

I use queries like

"UPDATE MAILSCH.MESSAGE "
            + "SET IDFOLDER=?, SUBJECT=?, CONTENT=?, CREATIONTIME=?, AD_FROM=?, AD_TO=?, STATUS=? "
            + "WHERE IDMESSAGE=?";

May I miss out IDFOLDER without changing query?

like image 595
Andrei N Avatar asked May 25 '10 09:05

Andrei N


People also ask

What are the limitation of PreparedStatement?

Following are the limitations of prepared statements: Since a PreparedStatement object represents only one SQL statement at a time, we can execute only one statement by one prepared statement object. To prevent injection attacks it does not allow more than one value to a place holder.

What happens if we don't close PreparedStatement?

Yes, you have to close the prepared statements ( PreparedStatement Object) and result sets as they may cause memory leakage.

Can I use same PreparedStatement multiple times?

You can execute a given prepared statement multiple times, passing different variables to it or setting the variables to different values before each execution.


2 Answers

No you can't. You need to conditionally insert that part of the SQL into the SQL string when needed.

like image 194
Joe Avatar answered Oct 12 '22 21:10

Joe


No, you'll have to write a second query that doesn't include the IDFOLDER column. All parameters have to be bound.

like image 20
duffymo Avatar answered Oct 12 '22 22:10

duffymo