Home  >  Article  >  Database  >  How Can I Access Hyphenated MySQL Column Names from Java?

How Can I Access Hyphenated MySQL Column Names from Java?

Linda Hamilton
Linda HamiltonOriginal
2024-11-18 21:29:02637browse

How Can I Access Hyphenated MySQL Column Names from Java?

Accessing Hyphenated Column Names in MySQL from Java

Despite searching extensively, you couldn't find a solution to accessing MySQL column names that contain hyphens. When attempting to use these names from Java code, the names break at the hyphen, causing them to become unrecognized. You've unsuccessfully tried substituting underscores in your code to resolve the issue.

To resolve this, you can enclose the column names within '`' (backticks) when referencing them in your Java code. This will allow you to access the columns without encountering the hyphenation error.

For example, if you have a column named 'air_port' in your MySQL database, you can access it in your Java code using:

ResultSet resultSet = statement.executeQuery("SELECT * FROM `air_port`");

The above is the detailed content of How Can I Access Hyphenated MySQL Column Names from Java?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn