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();
将会正确执行!