• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

NX: Reading from the DB

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am working on my Contractors assignment. Just started with trying to read from DB File.
I saw this in our forum
*********************************
The Data class reads from the file using the RandomAccessFile class. All you have to do is use this class to interrogate the database.
***********************************

I think RandomAccessFile is the easier way to read from the DB...Are thery any document, where I can learn more about this and start using it...Please help me on this.
Thanks
Karthik
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

 
Stefan Olson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I think RandomAccessFile is the easier way to read from the DB...Are thery any document, where I can learn more about this and start using it...Please help me on this.


http://java.sun.com/j2se/1.3/docs/api/java/io/RandomAccessFile.html
Get used to referencing the Sun API docs... it's the best way to go.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Karthik,
Sun have a very brief introduction to Random Access Files in their Essential Java Classestutorial.
Regards, Andrew
 
Karthik Balasubramanian
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Guys. Today I tried using Random Access File methods to read from the data base. The magic cookie, rec length, no of fields came out ok. And for the no of fields, name length was read, but when I tried to read the field name for the name length...It is not working. I am sure I am doing something wrong.
look at my code for this part:
char name[] = new char[nameLength],temp;
for (int count=0;count<name.length;count++){
temp=raf.readChar();
name[count]=temp;
It is returning some strange characters...Please suggest me what is the best way to read the field name and other fields. That would be of great help.
Thanks
Karthik
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Karthik,

The Sun Code Conventions recommends only having one declaration per line.
As for your problem .... I think if you check your instructions, you will find that the field names and field contents are stored as bytes. Possibly even US-ASCII 7 bit bytes (which will raise another question I am sure )
You are trying to read a Character which is two bytes long.
You need to read in bytes fully, then convert them to a String.
Regards, Andrew
 
You got style baby! More than this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic