473,657 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.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
Jul 19 '05 #1
2 3483
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.goo gle.com...
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 1
7) 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 I
nterceptor.java :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 v
a: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

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.goo gle.com...
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 1
7) 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 I
nterceptor.java :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 v
a: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

Jul 19 '05 #3

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

Similar topics

0
3940
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 version of this document can be found at: http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
9
5817
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 converting data in byte arrays. How can I accomplish this in C? I am using ansi C(gnu). Is there a way to have a byte datatype in c? Thanks, Rahul
3
1363
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 the web? Is it possible? Could you please provide some links where I could find the information? Thanks, Sridhar.
0
1705
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 using the split function and then inserts them into different fields of the database. But the problem is that the JSP ; token=line.split(" "); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
3
2092
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 columns returned by the query. However, I need to be able to determine the size of the varchar fields that are returned by the query. The obvious answer appeared to be to check the DataColumn.MaxLength property. However, after using the Fill method,...
1
1666
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 byte in character. 'LONGTEXT' datatype can store upto 4 byte and maximum length of 4,294,967,295 characters. But I need to store upto 100 bytes. How can I do this? Or is there any other database server which can solve this problem? Please help...
0
1665
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 database. I read data stored in database using a DbDataAdapter which fill a dataset. One of the columns DataType of the dataset is a System.Byte containing an array of bytes. (In the SqlServer database it is stored as VarBinary field). For...
3
5999
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 values, transfer those numeric values over ASP.NET. I had no problem doing this on my local computer, by getting the field with "cast(field as BINARY)" so that on ASP.NET I have a byte array.Then send every field of array over ASP.Net.
10
2897
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 show the code first.. private static extern int IntADsOpenObject(string path, string userName, string password, int flags,ref MyGuid iid, out object ppObject); struct MyGuid { public Int32...
0
8421
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8742
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8621
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7354
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.