File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Read Error: String index out of range: -1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Read Error: String index out of range: -1" Watch "Read Error: String index out of range: -1" New topic
Author

Read Error: String index out of range: -1

Jay X Brown
Ranch Hand

Joined: Jan 26, 2001
Posts: 51
hi all,
i am persistently getting the above-mentioned runtime error and at wit's end.
This code is designed to get parameters from a html form,
read data from two databases,
and output to an xml file.
Read Error: String index out of range: -1
For every 'customer' there are usually 3 addresses. It gets
stuck while reading the address table on the second itiration. I believe this is where this error is generated.
what am i doing wrong?
========*************====
[JUST WANTED TO TELL PEOPLE THAT I FIGURED IT OUT BY SLOW TRIAL AND ERROR. THE PROBLEM WAS SOME DATA MASSAGING WHERE I WAS TRYING TO TAKE OUT EXTRANEOUS DATA. MORE ON THAT IN THE JAVA GENERAL PAGE.]

=========
this is the code fragment where i think the error is occurring.

===================
the complete code is at:
http://y42.briefcase.yahoo.com/bc/jaybrown99/vwp2?.to k=bcMoy56A6cBKBmDZ&.dir=/Public&.dnm=custXMLwriter.java.java&.src=bc
===================

thanks, in advance, for your help.
jay

[This message has been edited by Jay Brown (edited March 26, 2001).]
[This message has been edited by Jay Brown (edited March 26, 2001).]
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I believe the actual problem is where you say:

It is important to realize that ResultSet.next() increments the cursor as well as returning the status. So your first "if", actually steps past the first column.
A better solution might be:

As an aside, it is generally considered good practice to explicitly declare the fields you are retrieving from a query instead of using "select * from whatever". This helps make your code robust if you inadvertently change the ordering of the columns in the table, or add another column which is not used by this code. It also helps make your code more readable to reviewers, as we can see what should be in each column
I hope this helps.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Jay X Brown
Ranch Hand

Joined: Jan 26, 2001
Posts: 51
thanks for the response, Frank.
turns out (as i noted in my editted message) that the problem was elsewhere. but thanks for the tips.
i had totally forgotten that results.next increments the cursor. and i'll include the column names next time.
thanks again.
i love this board!!
jay
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Read Error: String index out of range: -1