File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Using objects on a CSV file rather than a database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using objects on a CSV file rather than a database" Watch "Using objects on a CSV file rather than a database" New topic
Author

Using objects on a CSV file rather than a database

Eamon Nixon
Greenhorn

Joined: Jun 30, 2012
Posts: 10
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

Joined: Oct 13, 2005
Posts: 36508
    
  16
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

Joined: Jan 28, 2003
Posts: 3952
    
  17

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.


Steve
Eamon Nixon
Greenhorn

Joined: Jun 30, 2012
Posts: 10
Thanks Gents. I'll take a look at those links.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
You’re welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using objects on a CSV file rather than a database
 
Similar Threads
problem framing subquery...
UML questions, need answers
Streams but no IO allowed
Non-CSV, Flat File JDBC Driver
Design 01