Hibernate / MS SQL / Unicode - JDBC JAVA

This is a discussion on Hibernate / MS SQL / Unicode - JDBC JAVA ; Hi, I have a web-apps that sends unicode data to my servlet. I can save it ot he MS SQL server and when I read it using JDBC client (Squirrel), I can see the unicode correctly in the DB. I ...

+ Reply to Thread
Results 1 to 3 of 3

Hibernate / MS SQL / Unicode

  1. Default Hibernate / MS SQL / Unicode

    Hi,

    I have a web-apps that sends unicode data to my servlet. I can save it
    ot he MS SQL server and when I read it using JDBC client (Squirrel), I
    can see the unicode correctly in the DB.
    I use Hibernate to read/write to the DB.
    I Hibernate reference docs, I didn't find anything about unicode values.
    The funny thing is I can save correctly.... but when I try to query it
    doesn't work.
    A simple query like

    session.createQuery("from User where username='xxxxxx'");

    ( where 'xxxxx' is a unicode String)
    it returns nothing.
    I triied to add a capital "N":

    session.createQuery("from User where username=N'xxxxxx'");

    which shows a Hibernate error ( "unexpected token '??????'");

    Any idea as how I can write a "where" clause with Hibernate with unicode
    values?

    Thank you.

    --
    JSC

  2. Default Re: Hibernate / MS SQL / Unicode

    JScoobyCed wrote:
    > Hi,
    >
    > I have a web-apps that sends unicode data to my servlet. I can save
    > it ot he MS SQL server and when I read it using JDBC client (Squirrel),
    > I can see the unicode correctly in the DB.
    > I use Hibernate to read/write to the DB.
    > I Hibernate reference docs, I didn't find anything about unicode values.
    > The funny thing is I can save correctly.... but when I try to query it
    > doesn't work.
    > A simple query like
    >
    > session.createQuery("from User where username='xxxxxx'");
    >
    > ( where 'xxxxx' is a unicode String)
    > it returns nothing.


    Ok, found the solution...

    Have to use "Criteria"
    Criteria criter = session.createCriteria(User.class);
    criter = criter.add(Restrictions.eq("username", usern));
    List list = criter.list();

    --
    JSC

  3. Default Re: Hibernate / MS SQL / Unicode

    On 2005-11-22, JScoobyCed <pim@pam.poum> wrote:
    > JScoobyCed wrote:
    >> Hi,
    >>
    >> I have a web-apps that sends unicode data to my servlet. I can save
    >> it ot he MS SQL server and when I read it using JDBC client (Squirrel),
    >> I can see the unicode correctly in the DB.
    >> I use Hibernate to read/write to the DB.
    >> I Hibernate reference docs, I didn't find anything about unicode values.
    >> The funny thing is I can save correctly.... but when I try to query it
    >> doesn't work.
    >> A simple query like
    >>
    >> session.createQuery("from User where username='xxxxxx'");
    >>
    >> ( where 'xxxxx' is a unicode String)
    >> it returns nothing.

    >
    > Ok, found the solution...
    >
    > Have to use "Criteria"
    > Criteria criter = session.createCriteria(User.class);
    > criter = criter.add(Restrictions.eq("username", usern));
    > List list = criter.list();


    I'v got the feeling if you use a prepared statement that it will work
    too.


    --
    Met vriendelijke groeten,
    Tim Van Wassenhove <http://timvw.madoka.be>

+ Reply to Thread

Similar Threads

  1. Does unicode() equal to unicode(sys.getfilesystemencoding()) ?
    By Application Development in forum Python
    Replies: 1
    Last Post: 06-06-2007, 01:59 AM
  2. hibernate or ojb or ???
    By Application Development in forum JDBC JAVA
    Replies: 0
    Last Post: 10-20-2005, 04:18 AM
  3. Hibernate Help: Hibernate list of lists problem
    By Application Development in forum JDBC JAVA
    Replies: 0
    Last Post: 05-24-2005, 01:15 PM
  4. [HIBERNATE] [EVALUATION] - Gavin King Censors Hibernate Forum
    By Application Development in forum Java
    Replies: 2
    Last Post: 12-27-2004, 12:29 AM
  5. [HIBERNATE] [EVALUATION] - Gavin King Censors Hibernate Forum
    By Application Development in forum JDBC JAVA
    Replies: 0
    Last Post: 12-26-2004, 11:26 PM