ORA-00933:SQL 命令未正确结束:java



我正在从文本文件中获取域并将其逐个传递给查询。第一次查询执行正常..但是当它采用第二个域并将其传递给查询时,出现错误"ORA-00933:SQL 命令未正确结束" 下面是代码

sql.append("select person_org_id,profile_type_id as NEXUS, profile_option_id,profile_option_value  from TABLE1 ");
            sql.append(" where profile_type_id=1 and person_org_id in (select person_org_id from TABLE2 where ");
            sql.append(" account_id in (select account_id from TABLE3 where prod_id=10001 and prod_inst_name = ?)) ");
            ps = con.prepareStatement(sql.toString());
            System.out.println("----------checkpoint -----------");
            ps.setString(1,domain_name);
            System.out.println("----------checkpoint 4-----------");
            rs= ps.executeQuery();
            System.out.println("----------checkpoint 5-----------");

如果你在循环中有这段代码,并且你没有清除 StringBuilder 或使用一个新的,那么第二次,你将有两次 SQL 语句,这将解释错误。

如果一个简单的字符串就可以了,为什么要使用StringBuilder呢?SQL 语句中完全没有变化。当然,这可能是一个简化的例子。

此外,如果你在循环中执行此操作,并且SQL确实每次都是完全相同的,那么您只需准备一次语句,然后在循环中重复执行它。这就是准备好的发言的目的。

最新更新