This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using objects on a CSV file rather than a database

 
Eamon Nixon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have some programming experience only with databases but not OO programming, but I am trying to create a Library system. Loans and LoanLine has a 1.....* relationship. Thats fine. I know this unique fields and auto incremenets etc.
However, I'm trying to use a CSV file because its alien to me. Seems stupid as I know databases, yes probably is, but cant learn what I already know.
If I create a Loan file, how do I keep a unique Loan ID? or does Java have a wonderful API to help me do this CSV file stuff?
I will need two CSV files, Loan and LoanLine which will correspond to objects/classes.
e.g Loan file
1,Tom;
The LoanLine file
1, 1, Rocky,07/07/12;
1, 2, Matrix,07/07/12;
Tom takes out 2 dvds.

How do I create my next Loan as I will need to know the Loan file already contains #1.
The only way is to read the last line of the Loan file and get value up to the comma, then add 1 to this number when I create a new Loan object?
Create Loan object.
Read Loan file, get last number, add 1 for the ID.
Now create LoanLine object.
I'm not expecting a thorough explanation, but if somebody could point me in the right direction. Read up on String buffer or IO file or read up on ****, that would be fantastic and much appreciated.
My problem in summary is doing the stuff that database usually do with indexes and primary and foreign keys.
How will I check that a Dvd is not out on Loan?
Search for "Matrix,07/07/12" and if it doesn't exist in LoanLine, its available. Loanline is linked to movies.
Does Java have a special API that makes all this reading and writing to CSV files easy? This is basically my question. I'm also still at the design stage of classes and the reading and writing from csv files to objects is confusing me.
I hope this makes sense to someone. Lol


 
Campbell Ritchie
Sheriff
Pie
Posts: 49382
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don’t know. CSV files are a lot more difficult to use than they look, so we have an FAQ about all sorts of file formats, which should include CSV.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I have used the Ostermiller one pointed to on Campbell's link. It is good.

But CSV doesn't handle the logic of indexing and keys, and such. It is just a flat file format used for storage, akin to .txt but for columned data. If you want to do unique IDs then you will have to do that yourself.
 
Eamon Nixon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Gents. I'll take a look at those links.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49382
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You’re welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic