• 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

db access returning String

 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My assignment (URLyBird) specifies to have String array to be returned for read. I am searching for a method to replace readByte:byte with something like readString(offset, length):String.

DataInputStream is what I looked so far.

I would like to know any of the java library addresses this and provide a method like readString.

I understand readUTF is supposed to function so. But an offset and length cannot be specified. I will love to use readUTF. I just need to know how to tame it.

Please let me know your thoughts. I don't feel reading bytes and concatenating it to String is a good idea if a library function already exists.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following works for me:
1. create a byte[] of the correct length (found from record metadata)
2. use readFully(byte[])
3. use the String constructor that takes a byte[] argument

hope that helps
Steve
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stephen,
Thanks for your reply.

It works for me too. I don't like the idea of creating array bytes each time I read database. Hence I am planning to keep the byte array static or move to a MetaInfo object.

I was checking to see whether anybody tried anything else.

Jiju
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
one correction. Keeping a static reference to byte array will not work since it has to be shared with many users. Infact each thread has to have it's own byte array.

Hence Stephen's approach seems to be right. Pardon me for the thoughtless suggestion.
 
reply
    Bookmark Topic Watch Topic
  • New Topic