java.sql.SQLException: ORA-01006: 赋值变量不存在


String query= "select * from DM_MAP_"+mapIndex+ " t where t.viewName='"+vName+ "'";
System.out.println(query);
PreparedStatement pst=con.prepareStatement(query);
rs = pst.executeQuery();
执行是正确的。
使用绑定变量看看
String query= "select * from DM_MAP_2 where VIEWNAME='?' ";
PreparedStatement pst=con.prepareStatement(query);
pst.setString(1, "T_2_2");
rs = pst.executeQuery();
将会报错!:java.sql.SQLException: ORA-01006: 赋值变量不存在
要改成
String query= "select * from DM_MAP_2 where VIEWNAME=? ";
PreparedStatement pst=con.prepareStatement(query);
pst.setString(1, "T_2_2");
rs = pst.executeQuery();
将会正确执行!








你可能感兴趣的:(数据库,职场,休闲,ORA-01006)