Question

I am taking domains from a text file and passing it to a query one by one. for first time the query is executing fine .. but when it takes the second domain and passing it to query getting error "ORA-00933: SQL command not properly ended" Below is the code

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-----------");
Était-ce utile?

La solution

If you have this code in a loop, and you do not clear the StringBuilder or use a new one, then the second time around, you will have the SQL statement twice and that would explain the error.

Why use a StringBuilder at all if a simple String would do? There is no variation in the SQL statement at all. Of course, this may have been a simplified example.

Also, if you do this in a loop, and the SQL is indeed the exact same one every time, you could just prepare the statement once, and execute it repeatedly in the loop. That is kind of what prepared statements are for.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top