0

Now I using hql in query. The code is:

return session.createQuery(
                "from Company com "
                        + " where com.comId = "
                        + ":comId and com.phoneNumber = :phoneNumber")
                .setString("comId", comId).setString("phoneNumber",
                        phoneNumber).list();

the phoneNumber in DB is varchar2(255 char), and I using Oracle DB.

But this code can't work in java codes. If the phoneNumber is "999-000-0001", it can work. I can get a record. But if the phoneNumber is "USPersonal", I will not get the record.

In Company.java, the phoneNumber is String, and has get and set methods.

In DB, I using Sql Developer, I can get all of the above.

I don't know, why it is? Is the setString doesn't work?

leppie
  • 115,091
  • 17
  • 196
  • 297
mengya
  • 1
  • 1

1 Answers1

0

I have solve this problem.

Because in this case, the phoneNumber come from file. In file, I ignored there has some space in phoneNumber " USPersonal ", while in DB, it is "USPersonal" only.

So I didn't get this record.

The codes above are correct. How careless of me!

mengya
  • 1
  • 1