0

help me with the below issue please. With the below code

 if (con == null || con.isClosed()) con = DBBase.getNewConnection();
    sb = con.createStatement();

    resSet = sb.executeQuery("select * from  USERSAGGRS  where userid='" +user.getUserid()+ "'  AND  id='" +aggid+ "'  ");

when load jsp page I get this error:

java.sql.SQLException: ORA-00933: SQL command not properly ended

1
  • show the total section of your code please.so as to get an outlook of your program Commented Aug 23, 2015 at 5:07

1 Answer 1

1

Most likely the values of user.getUserid() and/or aggid are the problem. You can test it by printing the query and test that in any Oracle DBMS client.

System.out.println("select * from  USERSAGGRS  where userid='" +user.getUserid()+ "'  AND  id='" +aggid+ "'  ")

OTOH

The proper way to do is by using PreparedStatement

if (con == null || con.isClosed()) con = DBBase.getNewConnection();
    String SQL = "select * from  USERSAGGRS  where userid=?  AND  id=?"
    sb = con.prepareStatement(SQL);
    sb.setString(1,user.getUserid());
    sb.setString(2,aggid);
    resSet = sb.executeQuery();

By using PreparedStatement you can also avoid SQLInjections

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.