Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-24-2008, 11:29 PM
Member
 
Join Date: Aug 2007
Posts: 20
Rgfirefly24 is on a distinguished road
Update a record in Random access file
I have been given a program that will add and search through records from a random access file.
I need to add an update button so that i can change items in a record and replace the old record with the new one.

The problem is That when i execute the program that the update doesn't happen it just places a new record behind the one i want to update. It also doesn't put in anything but the name.

I have tried putting inputting a string with the name street city state and zip but i'm not sure how to parse it back out.

i know that i need to do something along these lines:

oldvariable = new name/street/city/state/zip(which ever I'm doing at the time)
Code:
jbtUpdate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ try{ long currentPosition = raf.getFilePointer(); UpdateAddress(currentPosition); } catch (IOException ex) { ex.printStackTrace(); } } }); /** Update a record at the specified position **/ public void UpdateAddress(long position){ try{ raf.seek(position); FixedLengthStringIO.UpdateFixedLengthString(jtfName.getText(), NAME_SIZE, raf); FixedLengthStringIO.UpdateFixedLengthString(jtfStreet.getText(), STREET_SIZE, raf); FixedLengthStringIO.UpdateFixedLengthString(jtfCity.getText(), CITY_SIZE, raf); FixedLengthStringIO.UpdateFixedLengthString(jtfState.getText(), STATE_SIZE, raf); FixedLengthStringIO.UpdateFixedLengthString(jtfZip.getText(), ZIP_SIZE, raf); } catch(IOException ex){ ex.printStackTrace(); } }
and

Code:
public static void UpdateFixedLengthString(String s, int size, DataOutput out) throws IOException{ char[] chars = new char[size]; s.getChars(0, Math.min(s.length(), size), chars, 0); for (int i = Math.min(s.length(), size); i < chars.length; i++) chars[i] = ' '; out.writeChars(new String(chars)); } }

Last edited by Rgfirefly24 : 04-24-2008 at 11:55 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-24-2008, 11:43 PM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 191
danielstoner is on a distinguished road
Hello, just a small piece of advice because I see this kind of posts a lot. The best way to ask for help is to structure your message like this in order:

1. Describe the problem, what you try to solve
2. Describe the solution, your design or algorithm
3. Describe the error/issue, what doesn't work as expected
4. Describe what you already tried in order to solve the problem
5. Show the code, as much as possible to be relevant, but don't flood me with thousands of irrelevant lines

I know this requires more effort from your side but it presents clear advantages to you:
- you actually think in a structured way about your problem and who knows you might actually solve it without any help
- you help us to help you; if you give me 1000 LOC without any explanation probably I won't read it

Sorry if this sounds like a rant or a flame but... this is what it is! ...eerrr, just joking, actually it is very honest advice. Take care man.
__________________
Daniel @ [
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-25-2008, 12:07 AM
Member
 
Join Date: Aug 2007
Posts: 20
Rgfirefly24 is on a distinguished road
updated my message
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
File Access Through Servlets bipinkrishna15 Java Servlet 1 05-27-2008 12:58 PM
how to access shared file/folder in LAN ksheetiz Networking 2 05-24-2008 06:54 AM
Random Access File JavaForums Java Blogs 0 12-26-2007 04:01 PM
Random Access Files concept AralX New To Java 2 12-25-2007 09:04 PM
variable access from another file riadmazloum AWT / Swing 1 08-06-2007 09:13 PM


All times are GMT +3. The time now is 03:09 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org