Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

connection to db file

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I just started the SCJD, I have a question on connecting the database file.
First I tried to just look at the content in the db file, but since this database is a non-relational, no table name and cannot be open in any DBMS I got, I realised JDBC and SQL statements cannot be used. So I open it in the normal file handling way, using FileInputStream, and I have got the content out from the file.
But when I display the content of the db file onto the scream, it is so unorganised and some data cannot be read and replaced by weird symbols on the screen, so it must not totally read this file correctly according to its format. I wonder am I using the right approach to read to this db file?
I appreciate for any comments and advices, thank you very much.
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Alex,
Does your specs say anything about the format of the db file?
Your assignment might be different, than mine for example, but from my specs I know how to read the size of each record field from the file and then the record field itself.
Regards,
Seid
 
Alex Leung
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, the format of the database file is actually: .db
I have got a little more progress on reading the file, I will briefly list what I did:
1. I read the .db file with RandomAccessFile or FileInputStream
2. According to the format of the Start of file section in the assignment spec, there are 4 bytes for magic cookie, 4 bytes for overall length for each record, and 2 bytes for number of fields. So I have create an array for each of these 'things', total of 3. To see what values they are, I first put the correct bytes into each array.
3. The 3 arrays now contains the bytes, then I convert them into string and display them on screen.
The result is not useful at all, looks like '2 faces icon' and a 'f' sign, I do know that probably is because it is not text for display but just some information. But I do know you will need to know the overall length of each field to work out the position of each record in the .db file, but I cannot retrieve such infomation using this approach.
There are other problems when I just display everything of the .db file on screen, a field of data seems to be missing - location. Also there is no 'owner' for the very last record.
Mmm... many problems here for me, anybody else also having trouble like this?
I appreciate for any comments and advises. Thank you.
 
Alex Leung
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I was miss reading the fields of my database, there are no field missing at all, but still cannot decode the start of file properly. I guess I will solve this too if I spend more tme on it.
 
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alex -
Take a look at this thread - hope it helps a little.
this thread
TJ
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic