• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Read Error: String index out of range: -1

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jay X Brown
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic