JDBC prepareStatement 不起作用

2021-12-21 00:00:00 mysql prepared-statement jdbc

我正在尝试使用 prepareStatement 函数.代码如下.执行后,它返回给我一堆 vlicense 字符串而不是值.

I'm trying to use the prepareStatement function. The code is below. After it executes, it returns me a bunch of vlicense strings instead of the values.

当代码完成statement.setString()时,语句变成:

When the code finishing the statement.setString(), the statement becomes:

select 'vlicense' from Vehicle

但是,它必须是:

select vlicense from Vehicle

没有引号.谁能告诉我有什么问题?

without the quotation marks. Can anyone tell me what's the problem?

statement = oConnection.prepareStatement("select ? from Vehicle");
String tempString = "vlicense";
statement.setString(1, tempString);
resultSet = statement.executeQuery();

推荐答案

您不能将参数标记用于列名、表名、数据类型名,或者基本上任何不是数据的东西.

You can't use parameter markers for column names, table names, data type names, or basically anything that isn't data.

相关文章