java - preparedStatement中怎么样传如 in(?)中的参数
天蓬老师
天蓬老师 2017-04-18 10:32:48
0
2
680

如下面的例子:
?中是一个列表,如'1','2','3'.
替换后应该是 in ('1','2','3'),但是我把'1','2','3'传进取却不能正确的执行取得结果,跟踪发现参数被当初一个字符串了里面的引号被转义了,变成in (''1','2','3'') ,导致结果不对,请问像sql中 in (?),preparedStatement设置参数要怎么处理?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
巴扎黑

Just watched it again in javapreparedStatement

should be handled like this:

PreparedStatement statement = connection.prepareStatement("Select * from test where field in (?)");
Array array = statement.getConnection().createArrayOf("VARCHAR", new Object[]{"A1", "B2","C3"});
statement.setArray(1, array);
ResultSet rs = statement.executeQuery();

or:

in(?,?,?)Then assign multiple times

小葫芦

http://fish198398.iteye.com/b...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!