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

Acces table

Kim Mirtens
Greenhorn

Joined: Dec 17, 2006
Posts: 21
I'm fairly new to java and I'm trying to make a simple program that accesses some data from a table. The table has about 12 columns and 100 rows and consists exclusively out of numbers. The rows are linked to each other and using data from one column I want to be able to access the data of an other column on the same row. I want to be able to write a get function which gives me a value back of a specific row based on an argument from a different column (on the same row).
How should I go about this? Should I put my table in a database? Is there something in java like struct in C and records in Pascal? Should I use 2D arrays? Should I make write a class which has all the columns as instance variables (making an object of each row)? Use an Arraylist or LinkedList? Basically what is the easiest option to do this?
[ December 29, 2006: Message edited by: Tim Pintens ]
Stephen Foy
Ranch Hand

Joined: Oct 17, 2005
Posts: 143
http://java.sun.com/docs/books/tutorial/jdbc/TOC.html


Stephen Foy - Microsoft Application Development Consultant
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30506
    
150

For the future, note we have a forum on JDBC.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11302
    
  16

JDBC sounds good to me, so off this thread goes!!!


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Kim Mirtens
Greenhorn

Joined: Dec 17, 2006
Posts: 21
I didn't know if a database was the best way to go. The only thing my program has to do is USE the values from the table. This table doesn't change; it only holds constants. Setting up a DB-connection just to use values, seemed kinda hard and maybe unnecessary if there was an other way (which I guess there is not).
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30506
    
150

Tim,
You are correct that a database isn't necessarily the best way to go. Since you mentioned it in your post, that was the way the advice went.

I would use a comma or tab delimited file with the data and read that in.
Kim Mirtens
Greenhorn

Joined: Dec 17, 2006
Posts: 21
I merely thought of DB as a possible solution, but was actually inquiring what was the best way to go.
If I just read the file, then how would I go abouut searching for values. Just use loops to scan all values (is there a function to search for values?)? Do I put the table in a 2D array or is it better to search and read on the fly.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30506
    
150

Tim,
Assuming you plan to use this data more than once, it is best to read it in and store it in a data structure of your choosing.

That structure may be a 2D array or it may be a map of custom objects. If your data has some sort of key (like an id number), the map will be easier to use. If all the fields are equally meaningful, you could use the 2D array. Or you could use a 1D array of Objects that you create.

There's no right and wrong on this. It depends on your data and preferences.
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

Originally posted by Tim Pintens:
I'm fairly new to java and I'm trying to make a simple program that accesses some data from a table. The table has about 12 columns and 100 rows and consists exclusively out of numbers. The rows are linked to each other and using data from one column I want to be able to access the data of an other column on the same row. I want to be able to write a get function which gives me a value back of a specific row based on an argument from a different column (on the same row).
How should I go about this? Should I put my table in a database? Is there something in java like struct in C and records in Pascal? Should I use 2D arrays? Should I make write a class which has all the columns as instance variables (making an object of each row)? Use an Arraylist or LinkedList? Basically what is the easiest option to do this?

[ December 29, 2006: Message edited by: Tim Pintens ]



We do not use 'structs' in Java. Instead you will make a class which will serve the same purpose in the beginning. So what you were thinking to do with struct, instead do with "class".
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Acces table