需要使用变量的地方用问号标明即可呀,然后给变量提供值就好呀。
如果你想把codeCol 等变量也用set方式,是不可以的。
?只能在select 语句where 后面,insert into语句set后面,update语句values后面。PreparedStatement ps= connection.prepareStatement(" select " + codeCol + " from " + table + " where " + descCol + "=?");
ps.setString(1, xxx);
ResultSet rs = ps.executeQuery();