May be this question has been answered before but I couldn't find it.
I am using a 2/3 yr old MySQL database which has hyphens in its column names. When I try to use these names from my Java code, the names are broken at the hyphen (e.g. air_port becomes air) and thus are not found. I tried replacing hyphens to underscores in my code hoping that the DB might treat them equally but that doesn't work.
How can I escape the hyphen or how can I access these columns ? Could this be an issue of the character set being used ?
Under SQL-92 table and field names should not: Contain SQL special characters like the hyphen/dash/minus character.
No, the hyphen is an operator, and you can't use that in the middle of an identifier.
To set a string with hyphen and numbers, you need to use single quotes. For example, 'Customer-1234-899', 'Customer-9383-901', etc.
Using special characters in column names can create a problem for the SQL queries that are used by Netcool/Impact. Netcool/Impact, in most cases, surrounds the column that contains the special characters with double quotation marks to avoid this issue. However, if the particular character is not listed in the impact.
enclose the names within `back-ticks`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With