Ngày tải lên :
24/10/2013, 09:15
... 03.500
82
Chapter 1 Fundamentals
You will notice at listing lines 53 through 57 that I chose to add some more records. I just
wanted to make things painfully obvious during the rest of the test. There is nothing really magic
about the values in those records, other than the fact they are easy to spot.
Pay special attention to listing line 82. Do you remember what I said earlier? I deliberately
left this line where it was to prove that statement. Now, let's take a look at the output.
roland@logikaldesktop:~/fuelsurcharge2$ javac doeHistory .java
roland@logikaldesktop:~/fuelsurcharge2$ javac testpackDoeHistory .java
roland@logikaldesktop:~/fuelsurcharge2$ java testpackDoeHistory
... those records, then attempt to add three
records which have the same primary key value.
What happens?
If you manage to get the records added, what happens when you attempt to reIndex()?
How about when you try to undelete?
91
Chapter 1 – Fundamentals
1.13
1.131.13
1.131.13
1.13
Deleting and Packing
Deleting and PackingDeleting and Packing
Deleting and PackingDeleting and Packing
Deleting and Packing
I mentioned much of this information earlier but we are going to go over it again in detail
because it tends to catch most newbies offguard even after they have been told a hundred times.
Deleting a record in an xBASE file does not physically delete the record (in most versions), nor
does ... The main menu/form for this application looks much like many
other applications implementing the CUA (Common User Access) interface. It has a main menu
across the top, and those drop down when you click on the entries.
96
Chapter 1 – Fundamentals
20070905,289.3
20070912,292.4
20070919,296.4
20070926,303.2
20071003,304.8
20071010,303.5
20071017,303.9
20071024,309.4
20071031,315.7
20071107,330.3
20071114,342.5
20071121,341.0
20071128,344.4
Actually it has over 100 lines in it, but I'm certainly not going to print it here. If you want,
you can visit the Department of Energy Web site and pull down the spreadsheet which has historic
diesel fuel prices, and create your own file.
In theory I could have done the Util call found at listing line 17 inside of the doeHistory class,
but I didn't have a warm and fuzzy feeling about the actual runtime scope of Util in all situations.
Feel free to experiment on your own with placing this call at various places in the class hierarchy.
Listing lines 26 through 78 serve no other purpose than to read a line from this CSV and load
it as a record in the database. Since I tried to implement localized error handling and provide
meaningful error messages, this code is a lot larger than you will see in most examples which
would simply trap all exceptions at one place and print a stack trace.
We should discuss this code briefly for those who have never tried to read lines in from a text
file before. First you have to create a FileReader object as I did at listing line 33. Once you have
done that you can create a BufferedReader object to read from and buffer the FileReader object
you just created as I did at listing line 40. The second parameter (4096) is an optional buffer size
in bytes. If you do not pass a buffer size, there is some value which gets used by default.
One has to use a BufferedReader object if one wishes to read a line of input at a time as we
do at listing line 46. The readLine() method of a BufferedReader object ensures that we either get
all characters as a String up to the newLine character or the end of the stream. ...