If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

So grab each user's info, create an instance of UserInfo with it, and put it in the Vector. When you loop through the Vector later, pull out each object and cast it as a UserInfo and access the attributes with the getter methods. This assumes you don't have a need to access just a specific user's info at any point. To do that you'd want a different data structure.

firstly, definately do what reinkesm says about making a User object to store all the data and use getter and setter methods to access it. Then store the User object in the Vector (or whatever else you want to store it in).

To display the data in a JTable you need to create a class that extends AbstractTableModel and overides all it's abstract methods. The JTable will use this object to determine what to display where. I won't explain how to use it here because sun have done a wonderful job of explaining it on their own. If you go here you'll be taken to suns "How to use JTable" page. I read this a few weeks ago and in half an hour i'd knocked up an AbstractTableModel to suit my needs. You'll need to add your Vector of information to this abstract table model object using a method of your own making, and the methods in the object will be tailored to your data so all the JTable has to do is ask "What should i put in row 2 column 5" and your data model will know what to tell it.

But are you seriously suggesting I use a UserClass to store the user details. I thought that was what the Access database did.!!!! When I need to get info I use JDBC and SELECT and when I need to set data I use UPDATE. My problem is that when I get ALL the records from the database I cant seperate them out into individual users using a Vector ie

Yep that's what I'm suggesting! The database is for persistence, a way to hold all of your data outside of the application. The Java class (ie: UserInfo) is for holding the data for use within the code. The UserInfo objects only live for a short amount of time, while the database lives forever.

Almost always, if you are getting a set of data from a database (ie: user information), the first thing you do is put it into an Object so you can easily pass it around to different methods and use it in your business logic, processing, etc.

Database calls are very very "expensive". Your goal is to read the data from the database once, store it in Java objects and manipulate it that way throughout your code, then when you are ready, and if it's needed, write any changes back out to the database.

But are you seriously suggesting I use a UserClass to store the user details. I thought that was what the Access database did.!!!! When I need to get info I use JDBC and SELECT and when I need to set data I use UPDATE. My problem is that when I get ALL the records from the database I cant seperate them out into individual users using a Vector ie

You just about answered your own question there. You suggested a plan for the program (using the database to get and set data), thought it through a bit, and then realised it's huge limitations. A user class wouldn't simply store the data in your program, it would manage it too. It will validate the input you're trying to write to the database (eg Date of Birth should be a valid date, not a random bunch of characters, or age should be a valid number, not a word). Also, it encapsulates and greatly simplifies your program. You only need to write the code once, and any number of users can be represented by it. If you alter it, it alters it EVERYWHERE you call one of it's mehtods. If theres something wrong with it you can easily seperate it from the rest of your program and test it independant of anything else that your program might do. You never have to worry about things like "if i change this line here, will another line all the way over there still work" because it's all internal to the UserClass only.

Also, as reinkesm pointed out, accessing the database takes a lot of system resources. I doubt you could do anything your computer couldn't handle with a simple database in a simple situation, but imagine if there were potentially thousands of people using the database all at once (such as an online store). If they repeatedly asked to see some bit of information about themselves it would clog the entire system up. whereas if the system got their info once and stored it then there wouldn't be such a problem. Many large database systems (such as banks) only perform intensive transactions once a day so the bandwidth isn't constantly clogged up.

Re: Reading from Vector

Originally posted by Green_Manalishi in the Vector each record is stored sequentially

well thats a daft idea... the whole idea of a Vector storing objects is that it is a more flexible storage container than a single array.

at the moment you effectively have a one dimensional array.. suppsoe you have 3 fields per record and 3 records, youve done this:

String[] details = new String[9];

and then stored the details sequentially in the array..

If you go 2 dimensional you will have a data model that actually matches how a JTable looks.

You dont necessarily need to create a custom object for your records but remember that java is an OBJECT ORIENTED programming language... you SHOULD create objects.. youre modelling users, create a User object. Then you can have a sequence of User objects in your vector.

If thats all a bit complicated, dont forget that in java, an array IS AN OBJECT no matter what it holds... yup.. tis true, int[] myInts = new int[10] is actually an object.. so if you cant be bothered making an object for your users, just shove all their details into a string array and shove the array into the Vector...

Thanks to your efforts I am now beginning to see some light in this dark tunnel.

Funnily enough I have tried using Hashtables, Hashmaps ArrayLists and Vectors and have came full circle again. The annoying thing is that it takes so much effort just to advance a wee bit in the implementation phase.

Just one more question before I kill this topic off.

one field of my user details is a photo which is stored in the database as an Object and in Java.

Each time I retrieve it I just get a hex dump of the bitmap appear on my screen. Is there an easy method for handling images between access and my Java program?

you should convert the photo into a BufferedImage, or ImageIcon or something like that, in java, then use an ObjectOutputStream when you upload it to the database, and store it in a BLOB. When the time comes to read the Blob, use an ObjectInputStream, and read the data back into an Object, then cast the Object into what it is supposed to be, e.g. a BufferedImage

alternatively.. just copy the image file to the database server, DONT put it in the database, and then store the PATH to the image, in the db.. upon retrieve, download the image from the specified path and put it into your app. Better.

Originally posted by reinkesm So grab each user's info, create an instance of UserInfo with it, and put it in the Vector. When you loop through the Vector later, pull out each object and cast it as a UserInfo and access the attributes with the getter methods. This assumes you don't have a need to access just a specific user's info at any point. To do that you'd want a different data structure. [/B]

I have done exactly as you said but when I try and get the Employee(UserInfo) back out again, I cant get it into the correct format...for example

I store the userdetails in an instance of Employee then add this to an ArrayList

When I iterate through the ArrayList I can get the individual Employee objects out using

Originally posted by reinkesm So grab each user's info, create an instance of UserInfo with it, and put it in the Vector. When you loop through the Vector later, pull out each object and cast it as a UserInfo and access the attributes with the getter methods. This assumes you don't have a need to access just a specific user's info at any point. To do that you'd want a different data structure. [/B]

I have done exactly as you said but when I try and get the Employee(UserInfo) back out again, I cant get it into the correct format...for example

I store the userdetails in an instance of Employee then add this to an ArrayList

When I iterate through the ArrayList I can get the individual Employee objects out using

allData.add(e);//add each iterated Employee to the ArrayList
more = rs.next();
}

rs.close();
stmt.close();//
} catch (SQLException e) {}
//Code used to see if I can get it back in its native form
for (int i= 0;i<allData.size();i++){
Employee r = allData.get(i);
// do something with r (Employee)

Originally posted by reinkesm So grab each user's info, create an instance of UserInfo with it, and put it in the Vector. When you loop through the Vector later, pull out each object and cast it as a UserInfo and access the attributes with the getter methods. This assumes you don't have a need to access just a specific user's info at any point. To do that you'd want a different data structure. [/B]

I have done exactly as you said but when I try and get the Employee(UserInfo) back out again, I cant get it into the correct format...for example

I store the userdetails in an instance of Employee then add this to an ArrayList

When I iterate through the ArrayList I can get the individual Employee objects out using