我有一张表,其中有一列名称为:bureau d'étude
当我进行选择时:
String sql = "select bureau d'étude from table";
服务器显示语法错误。如何隐藏或替换这个撇号?
最佳答案
你真的应该使用 PreparedStatement
来避免这些问题,从而避免 SQL 注入(inject):
PreparedStatement statementSelect;
String sql = "select ? from ?";
try
{
statementSelect = myConnection.prepareStatement(sql);
statementSelect.setString(1,"bureau d'étude");
statementSelect.setString(2,"table");
statementSelect.executeQuery();
}
catch (SQLException e )
{
//handle this
}
关于java - 从 mysql 数据库中选择一个带撇号的列名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16940474/