MySql reading BYTE datatype as String in Java

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan

    #1

    MySql reading BYTE datatype as String in Java

    Hello.

    I have recently tried upgrading the MySql connector for my servlet
    from 2.0.4 to 3.0.9. I have found a minor limitation in 2.0.4 and was
    hoping that 3.0.9 would fix it. However, now I am having a serious
    problem with the latest connector. During login, it seems to me that
    when validating the password, which is stored as a byte array in the
    database, the MySql connector is passing back the password info as a
    Byte. The exception I receive is the following:

    Error while processing request: java.lang.Illeg alArgumentExcep tion
    at sun.reflect.Uns afeObjectFieldA ccessorImpl.set (UnsafeObjectFi eldAccessorImpl .java:63)
    at java.lang.refle ct.Field.set(Fi eld.java:519)
    at nurse.servlet.D BServer.get(DBS erver.java:206)
    at nurse.servlet.S QLTables.getEmp loyee(SQLTables .java:94)
    at nurse.servlet.M ainServlet.doPo st(MainServlet. java:112)
    at javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java)
    at javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java)
    at org.apache.tomc at.facade.Servl etHandler.doSer vice(ServletHan dler.java:574)
    at org.apache.tomc at.core.Handler .invoke(Handler .java:322)
    at org.apache.tomc at.core.Handler .service(Handle r.java:235)
    at org.apache.tomc at.facade.Servl etHandler.servi ce(ServletHandl er.java:485)
    at org.apache.tomc at.core.Context Manager.interna lService(Contex tManager.java:9 17)
    at org.apache.tomc at.core.Context Manager.service (ContextManager .java:833)
    at org.apache.tomc at.modules.serv er.Http10Interc eptor.processCo nnection(Http10 Interceptor.jav a:176)
    at org.apache.tomc at.util.net.Tcp WorkerThread.ru nIt(PoolTcpEndp oint.java:494)
    at org.apache.tomc at.util.threads .ThreadPool$Con trolRunnable.ru n(ThreadPool.ja va:516)
    at java.lang.Threa d.run(Thread.ja va:536)

    However, when I trace through the code, I find that it is crashing
    when it reads the password field by mapping it as a String rather than
    a BYTE.

    It crashes in the following code:
    Object val = recs.get(j);

    ....

    if (val==null)
    f.set(answers[i], null);

    ....

    else if (val instanceof byte[]) {
    Object o = null;
    try {
    ObjectInputStre am in = new ObjectInputStre am(new
    ByteArrayInputS tream((byte[])val));
    o = in.readObject() ;
    in.close();
    }
    catch (Exception e) {
    if (!(answers[i] instanceof LogRecord))
    throw e;
    }
    f.set(answers[i], o);
    }
    else
    f.set(answers[i], val); <--- CRASHES HERE

    The problem is that it should get caught in the else if just above the
    last else. Now, the old mySql connector works fine, so I am curious
    if something happened in the newer version. This is just a strange
    problem. Does anyone have any ideas as to where to look to fix it?

    Thanks in advance
    Dan
  • Lukas Bradley

    #2
    Re: MySql reading BYTE datatype as String in Java

    I need more Java code.

    What are f and answers declared as? What does the f.set() method do?

    I need to see the query, and the code where you are getting it out of the
    database.

    Lukas



    "Dan" <zhanngol@yahoo .com> wrote in message
    news:75c66504.0 311250734.48f2c 65f@posting.goo gle.com...[color=blue]
    > Hello.
    >
    > I have recently tried upgrading the MySql connector for my servlet
    > from 2.0.4 to 3.0.9. I have found a minor limitation in 2.0.4 and was
    > hoping that 3.0.9 would fix it. However, now I am having a serious
    > problem with the latest connector. During login, it seems to me that
    > when validating the password, which is stored as a byte array in the
    > database, the MySql connector is passing back the password info as a
    > Byte. The exception I receive is the following:
    >
    > Error while processing request: java.lang.Illeg alArgumentExcep tion
    > at[/color]
    sun.reflect.Uns afeObjectFieldA ccessorImpl.set (UnsafeObjectFi eldAccessorImpl .
    java:63)[color=blue]
    > at java.lang.refle ct.Field.set(Fi eld.java:519)
    > at nurse.servlet.D BServer.get(DBS erver.java:206)
    > at nurse.servlet.S QLTables.getEmp loyee(SQLTables .java:94)
    > at nurse.servlet.M ainServlet.doPo st(MainServlet. java:112)
    > at javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java)
    > at javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java)
    > at[/color]
    org.apache.tomc at.facade.Servl etHandler.doSer vice(ServletHan dler.java:574)[color=blue]
    > at org.apache.tomc at.core.Handler .invoke(Handler .java:322)
    > at org.apache.tomc at.core.Handler .service(Handle r.java:235)
    > at[/color]
    org.apache.tomc at.facade.Servl etHandler.servi ce(ServletHandl er.java:485)[color=blue]
    > at[/color]
    org.apache.tomc at.core.Context Manager.interna lService(Contex tManager.java:9 1
    7)[color=blue]
    > at org.apache.tomc at.core.Context Manager.service (ContextManager .java:833)
    > at[/color]
    org.apache.tomc at.modules.serv er.Http10Interc eptor.processCo nnection(Http10 I
    nterceptor.java :176)[color=blue]
    > at[/color]
    org.apache.tomc at.util.net.Tcp WorkerThread.ru nIt(PoolTcpEndp oint.java:494)[color=blue]
    > at[/color]
    org.apache.tomc at.util.threads .ThreadPool$Con trolRunnable.ru n(ThreadPool.ja v
    a:516)[color=blue]
    > at java.lang.Threa d.run(Thread.ja va:536)
    >
    > However, when I trace through the code, I find that it is crashing
    > when it reads the password field by mapping it as a String rather than
    > a BYTE.
    >
    > It crashes in the following code:
    > Object val = recs.get(j);
    >
    > ...
    >
    > if (val==null)
    > f.set(answers[i], null);
    >
    > ...
    >
    > else if (val instanceof byte[]) {
    > Object o = null;
    > try {
    > ObjectInputStre am in = new ObjectInputStre am(new
    > ByteArrayInputS tream((byte[])val));
    > o = in.readObject() ;
    > in.close();
    > }
    > catch (Exception e) {
    > if (!(answers[i] instanceof LogRecord))
    > throw e;
    > }
    > f.set(answers[i], o);
    > }
    > else
    > f.set(answers[i], val); <--- CRASHES HERE
    >
    > The problem is that it should get caught in the else if just above the
    > last else. Now, the old mySql connector works fine, so I am curious
    > if something happened in the newer version. This is just a strange
    > problem. Does anyone have any ideas as to where to look to fix it?
    >
    > Thanks in advance
    > Dan[/color]


    Comment

    • Lukas Bradley

      #3
      Re: MySql reading BYTE datatype as String in Java

      I need more Java code.

      What are f and answers declared as? What does the f.set() method do?

      I need to see the query, and the code where you are getting it out of the
      database.

      Lukas



      "Dan" <zhanngol@yahoo .com> wrote in message
      news:75c66504.0 311250734.48f2c 65f@posting.goo gle.com...[color=blue]
      > Hello.
      >
      > I have recently tried upgrading the MySql connector for my servlet
      > from 2.0.4 to 3.0.9. I have found a minor limitation in 2.0.4 and was
      > hoping that 3.0.9 would fix it. However, now I am having a serious
      > problem with the latest connector. During login, it seems to me that
      > when validating the password, which is stored as a byte array in the
      > database, the MySql connector is passing back the password info as a
      > Byte. The exception I receive is the following:
      >
      > Error while processing request: java.lang.Illeg alArgumentExcep tion
      > at[/color]
      sun.reflect.Uns afeObjectFieldA ccessorImpl.set (UnsafeObjectFi eldAccessorImpl .
      java:63)[color=blue]
      > at java.lang.refle ct.Field.set(Fi eld.java:519)
      > at nurse.servlet.D BServer.get(DBS erver.java:206)
      > at nurse.servlet.S QLTables.getEmp loyee(SQLTables .java:94)
      > at nurse.servlet.M ainServlet.doPo st(MainServlet. java:112)
      > at javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java)
      > at javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java)
      > at[/color]
      org.apache.tomc at.facade.Servl etHandler.doSer vice(ServletHan dler.java:574)[color=blue]
      > at org.apache.tomc at.core.Handler .invoke(Handler .java:322)
      > at org.apache.tomc at.core.Handler .service(Handle r.java:235)
      > at[/color]
      org.apache.tomc at.facade.Servl etHandler.servi ce(ServletHandl er.java:485)[color=blue]
      > at[/color]
      org.apache.tomc at.core.Context Manager.interna lService(Contex tManager.java:9 1
      7)[color=blue]
      > at org.apache.tomc at.core.Context Manager.service (ContextManager .java:833)
      > at[/color]
      org.apache.tomc at.modules.serv er.Http10Interc eptor.processCo nnection(Http10 I
      nterceptor.java :176)[color=blue]
      > at[/color]
      org.apache.tomc at.util.net.Tcp WorkerThread.ru nIt(PoolTcpEndp oint.java:494)[color=blue]
      > at[/color]
      org.apache.tomc at.util.threads .ThreadPool$Con trolRunnable.ru n(ThreadPool.ja v
      a:516)[color=blue]
      > at java.lang.Threa d.run(Thread.ja va:536)
      >
      > However, when I trace through the code, I find that it is crashing
      > when it reads the password field by mapping it as a String rather than
      > a BYTE.
      >
      > It crashes in the following code:
      > Object val = recs.get(j);
      >
      > ...
      >
      > if (val==null)
      > f.set(answers[i], null);
      >
      > ...
      >
      > else if (val instanceof byte[]) {
      > Object o = null;
      > try {
      > ObjectInputStre am in = new ObjectInputStre am(new
      > ByteArrayInputS tream((byte[])val));
      > o = in.readObject() ;
      > in.close();
      > }
      > catch (Exception e) {
      > if (!(answers[i] instanceof LogRecord))
      > throw e;
      > }
      > f.set(answers[i], o);
      > }
      > else
      > f.set(answers[i], val); <--- CRASHES HERE
      >
      > The problem is that it should get caught in the else if just above the
      > last else. Now, the old mySql connector works fine, so I am curious
      > if something happened in the newer version. This is just a strange
      > problem. Does anyone have any ideas as to where to look to fix it?
      >
      > Thanks in advance
      > Dan[/color]


      Comment

      Working...