473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

MySql reading BYTE datatype as String in Java

Dan
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.IllegalArgumentException
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(Unsa feObjectFieldAccessorImpl.java:63)
at java.lang.reflect.Field.set(Field.java:519)
at nurse.servlet.DBServer.get(DBServer.java:206)
at nurse.servlet.SQLTables.getEmployee(SQLTables.java :94)
at nurse.servlet.MainServlet.doPost(MainServlet.java: 112)
at javax.servlet.http.HttpServlet.service(HttpServlet .java)
at javax.servlet.http.HttpServlet.service(HttpServlet .java)
at org.apache.tomcat.facade.ServletHandler.doService( ServletHandler.java:574)
at org.apache.tomcat.core.Handler.invoke(Handler.java :322)
at org.apache.tomcat.core.Handler.service(Handler.jav a:235)
at org.apache.tomcat.facade.ServletHandler.service(Se rvletHandler.java:485)
at org.apache.tomcat.core.ContextManager.internalServ ice(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(Cont extManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor .processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(P oolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java: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 {
ObjectInputStream in = new ObjectInputStream(new
ByteArrayInputStream((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
Jul 19 '05 #1
2 3464
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" <zh******@yahoo.com> wrote in message
news:75**************************@posting.google.c om...
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.IllegalArgumentException
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(Unsa feObjectFieldAccessorImpl.
java:63) at java.lang.reflect.Field.set(Field.java:519)
at nurse.servlet.DBServer.get(DBServer.java:206)
at nurse.servlet.SQLTables.getEmployee(SQLTables.java :94)
at nurse.servlet.MainServlet.doPost(MainServlet.java: 112)
at javax.servlet.http.HttpServlet.service(HttpServlet .java)
at javax.servlet.http.HttpServlet.service(HttpServlet .java)
at org.apache.tomcat.facade.ServletHandler.doService( ServletHandler.java:574) at org.apache.tomcat.core.Handler.invoke(Handler.java :322)
at org.apache.tomcat.core.Handler.service(Handler.jav a:235)
at org.apache.tomcat.facade.ServletHandler.service(Se rvletHandler.java:485) at org.apache.tomcat.core.ContextManager.internalServ ice(ContextManager.java:91
7) at org.apache.tomcat.core.ContextManager.service(Cont extManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor .processConnection(Http10I
nterceptor.java:176) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(P oolTcpEndpoint.java:494) at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.jav
a:516) at java.lang.Thread.run(Thread.java: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 {
ObjectInputStream in = new ObjectInputStream(new
ByteArrayInputStream((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

Jul 19 '05 #2
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" <zh******@yahoo.com> wrote in message
news:75**************************@posting.google.c om...
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.IllegalArgumentException
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(Unsa feObjectFieldAccessorImpl.
java:63) at java.lang.reflect.Field.set(Field.java:519)
at nurse.servlet.DBServer.get(DBServer.java:206)
at nurse.servlet.SQLTables.getEmployee(SQLTables.java :94)
at nurse.servlet.MainServlet.doPost(MainServlet.java: 112)
at javax.servlet.http.HttpServlet.service(HttpServlet .java)
at javax.servlet.http.HttpServlet.service(HttpServlet .java)
at org.apache.tomcat.facade.ServletHandler.doService( ServletHandler.java:574) at org.apache.tomcat.core.Handler.invoke(Handler.java :322)
at org.apache.tomcat.core.Handler.service(Handler.jav a:235)
at org.apache.tomcat.facade.ServletHandler.service(Se rvletHandler.java:485) at org.apache.tomcat.core.ContextManager.internalServ ice(ContextManager.java:91
7) at org.apache.tomcat.core.ContextManager.service(Cont extManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor .processConnection(Http10I
nterceptor.java:176) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(P oolTcpEndpoint.java:494) at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.jav
a:516) at java.lang.Thread.run(Thread.java: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 {
ObjectInputStream in = new ObjectInputStream(new
ByteArrayInputStream((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

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
9
by: rahul | last post by:
Hi!, I have a java program that receives data via sockets from a C program. The java program has to recieve the data in byte format. I need to send character arrays from the C side after...
3
by: Sridhar | last post by:
Hi, I need to read a pdf file which is on my hard drive and put it in the sql server database. Once placed in the sql server, I again need to read that file from the database and display it on...
0
by: nrip | last post by:
Dear All, I am facing a very peculiar problem. I am reading a CSV file from my JSP code and trying to insert them into MYSQL database. the program first reads a line and then splits it into words...
3
by: Oenone | last post by:
I have a project that creates a SqlDataAdapter and uses its Fill method to fill a DataTable with data from a user-provided query. From there I can obviously access details about the rows and...
1
by: deepaks85 | last post by:
Dear Friends, If I have a text file more than 8 byte or upto 100 byte, how can I insert the data of that text file into mysql table. As per as I am concern there is not any datatype more than 4...
0
by: OscarPiacenza | last post by:
Hello all. :) My name is Oscar and I’m a novice on XML and dataset arguments. I need some help to resolve (and understand :) ) the following problem: I have stored some data in a SqlServer...
3
by: ist | last post by:
Hi, I am trying to get (and transfer over ASP.NET) some encrypted data from some MySQL fields. Since the data contains many unicode characters, I tried to get the data as a series of ASCII...
10
by: ShadowLocke | last post by:
I'm looking for a better understanding of whats going on with the code i write. I have come across something that I thought I understood but its not working as expected. Its hard to explain so let me...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.