How to quote/escape identifiers such as column names with JDBC?

前端 未结 3 1045
走了就别回头了
走了就别回头了 2021-01-17 16:29

Different database servers use different ways to quote and escape identifiers.

E.g. \"foo bar\" vs `foo bar` vs [foo bar], or \"10\"\"\" vs \"10\\\"\", or identifier

3条回答
  •  深忆病人
    2021-01-17 16:57

    I think the answer to your question is that if you are writing a database neutral application using JDBC, then you need to use database neutral names, and not things that require special escaping per database vendor.

    There is nothing I know of in the JDBC which supports that. A ORM product will deal with such things.

    Edit: If you are writing an ORM, then I would think need a seperate SQL generation class for each supported database, just to handle the various syntax involved, so you would have to write that. You can certainly look at the source code of the various open source ORM's out there and see how they handle it.

提交回复
热议问题