JDBC prepareStatement 不起作用 [英] JDBC prepareStatement doesn't work

查看:33
本文介绍了JDBC prepareStatement 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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.

这篇关于JDBC prepareStatement 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆