Variable column names using prepared statements

后端 未结 7 761

I was wondering if there was anyway to specify returned column names using prepared statements.

I am using MySQL and Java.

When I try it:

St         


        
7条回答
  •  暖寄归人
    2020-11-22 08:48

    The accepted answer is not actually correct. While the OP approach indicated a bad DB design, it might be required by the business logic (for instance a MySQL IDE)

    Anyway, for MySQL prepared statements, what you need to know is that ? is for values, but if you need to escape column names, table names etc, use ?? instead.

    Something like this will work:

    SELECT ??, ??, ?? FROM ?? WHERE ?? < ? 
    

    Set values to ['id', 'name', 'address', 'user', 'id', 100]

提交回复
热议问题