java qr code reader example IMPLEMENTING THE INVESTMENT QUOTE PERSISTENT STORAGE IN KJAVA in Java

Painting QR Code in Java IMPLEMENTING THE INVESTMENT QUOTE PERSISTENT STORAGE IN KJAVA

IMPLEMENTING THE INVESTMENT QUOTE PERSISTENT STORAGE IN KJAVA
Encoding QR-Code In Java
Using Barcode generation for Java Control to generate, create QR-Code image in Java applications.
www.OnBarcode.com
Recognize QR Code JIS X 0510 In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
String dbName = "QuoteData"; int dbType = 0x494E5653; //'INVS' int dbCreator = 0x43415454; //'CATT'
UPCA Creator In Java
Using Barcode printer for Java Control to generate, create UPC-A Supplement 2 image in Java applications.
www.OnBarcode.com
Draw UPC-A Supplement 5 In Java
Using Barcode generation for Java Control to generate, create UPC-A Supplement 2 image in Java applications.
www.OnBarcode.com
q w e
Encode Code128 In Java
Using Barcode encoder for Java Control to generate, create Code 128A image in Java applications.
www.OnBarcode.com
Barcode Creator In Java
Using Barcode generator for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
com.sun.kjava.Database quoteDB = new Database (dbType, dbCreator, Database.READWRITE); if (!quoteDB.isOpen()) { Database.create(0, dbName, dbCreator, dbType, false); quoteDB = new Database (dbType, dbCreator, Database.READWRITE); }
Painting QR Code ISO/IEC18004 In Java
Using Barcode generator for Java Control to generate, create Denso QR Bar Code image in Java applications.
www.OnBarcode.com
Encode Leitcode In Java
Using Barcode generation for Java Control to generate, create Leitcode image in Java applications.
www.OnBarcode.com
q w e
Quick Response Code Generator In VS .NET
Using Barcode encoder for Visual Studio .NET Control to generate, create QR Code ISO/IEC18004 image in .NET framework applications.
www.OnBarcode.com
Decoding QR Code In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
The database typeID The database creatorID Open or create the investment database With the open database, we first determine if there is an existing record for the given symbol. Unlike in the MIDP RMS, there are no convenience objects for filtering the database or enumerating through records. In KJava, enumerating through the database must be done using a loop, reading, and checking each record in the database. Inside of a for loop that starts at 0 and potentially goes to the full number of records in the database, we must read each record with a call to getRecord(int recordNumber) and determine if the record contains the symbol provided by the customer.
Reading ECC200 In Visual Basic .NET
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
Encode Denso QR Bar Code In None
Using Barcode generator for Software Control to generate, create QR image in Software applications.
www.OnBarcode.com
boolean found = false; int n = quoteDB.getNumberOfRecords(); for (int i = 0; i<n; i++) { byte[] raw = quoteDB.getRecord(i); if ((new String(raw)).startsWith(symbol + ';')) { found = true; newRecord += ';' + getLastPrice(raw); byteRec = newRecord.getBytes(); quoteDB.setRecord(i, byteRec); break; } }
GTIN - 12 Printer In None
Using Barcode printer for Software Control to generate, create UPC-A Supplement 5 image in Software applications.
www.OnBarcode.com
Printing DataMatrix In Java
Using Barcode generation for Eclipse BIRT Control to generate, create Data Matrix ECC200 image in Eclipse BIRT applications.
www.OnBarcode.com
The data stored in a Palm OS database comes out as a byte array. Because the symbol of the investment is stored in the front part of the data, we can simply check to see if the data, converted to a string, begins with the investment symbol. If so, we have a matching database record, indicating that a previous quote is stored in the database. When updating an existing record, the last current price becomes the new historical price. (Figure 10.2)
EAN / UCC - 13 Printer In VS .NET
Using Barcode generation for Reporting Service Control to generate, create EAN13 image in Reporting Service applications.
www.OnBarcode.com
Draw Data Matrix 2d Barcode In Java
Using Barcode maker for Android Control to generate, create Data Matrix ECC200 image in Android applications.
www.OnBarcode.com
Figure 10.2 When the application retrieves a new investment price for which an existing price already exists in the database, then the old price is made the historical price and the new price is made the current price.
GS1 - 13 Drawer In None
Using Barcode drawer for Microsoft Word Control to generate, create EAN13 image in Word applications.
www.OnBarcode.com
Barcode Scanner In VS .NET
Using Barcode scanner for VS .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Current price MMM 120.55; 113,45;
Generate Barcode In VB.NET
Using Barcode encoder for .NET Control to generate, create Barcode image in VS .NET applications.
www.OnBarcode.com
GTIN - 13 Generator In Visual C#.NET
Using Barcode drawer for VS .NET Control to generate, create EAN13 image in VS .NET applications.
www.OnBarcode.com
Historical price 113,45;
CHA PTE R 10
KJAVA DATA STORAGE
To assist in getting this data from the existing byte array record, another method is used to convert the byte array back to a string and to extract the last price from the string.
private String getLastPrice(byte[] rec) { String recString = new String(rec); int dollarPos = recString.indexOf(';'); int centPos = recString.indexOf(';',dollarPos+1); int centEnd = recString.indexOf(';',centPos + 1); if (centEnd > 0) //had a historical price return recString.substring(dollarPos+1,centEnd); else //no previous historical price return recString.substring(dollarPos+1); }
Get the position of the last price within the string
Return the current price string, regardless of a historical price
The getLastPrice() method, developed in the MIDP tutorial application implementation, is a byte array-to-string converter with some string manipulation to find the appropriate dollar and cent values stored in between the appropriate ; character delimiters. In the case where no investment record is found for an investment symbol provided, a new record must be added to the database. This is accomplished using the addRecord() method. The argument passed to the addRecord() method is the new record data converted into a byte array.
if (!found) { byteRec = newRecord.getBytes(); quoteDB.addRecord(byteRec); }
Finally, don t forget to close the database with a call to the close() method after storing or updating the investment quote. All together, the new two methods added to the ObtainQuoteSpotlet look like the code in listing 10.1.
Listing 10.1 The getLastPrice and storePrice methods in ObtainQuoteSpotlet
private String getLastPrice(byte[] rec) { String recString = new String(rec); int dollarPos = recString.indexOf(';'); int centPos = recString.indexOf(';',dollarPos+1); int centEnd = recString.indexOf(';',centPos + 1); if (centEnd > 0) //had a historical price return recString.substring(dollarPos+1,centEnd); else //no previous historical price return recString.substring(dollarPos+1); } private void storePrice(String symbol, int[] price) { String newRecord = symbol + ";" + price[0] + ";" + price[1]; byte[] byteRec; String dbName = "QuoteData"; int dbType = 0x494E5653; //'INVS'
IMPLEMENTING THE INVESTMENT QUOTE PERSISTENT STORAGE IN KJAVA
int dbCreator = 0x43415454;
//'CATT'
com.sun.kjava.Database quoteDB = new Database (dbType, dbCreator, Database.READWRITE); if (!quoteDB.isOpen()) { Database.create(0, dbName, dbCreator, dbType, false); quoteDB = new Database (dbType, dbCreator, Database.READWRITE); } boolean found = false; int n = quoteDB.getNumberOfRecords(); for (int i = 0; i<n; i++) { byte[] raw = quoteDB.getRecord(i); if ((new String(raw)).startsWith(symbol + ';')) { found = true; newRecord += ';' + getLastPrice(raw); byteRec = newRecord.getBytes(); quoteDB.setRecord(i, byteRec); break; } } if (!found) { byteRec = newRecord.getBytes(); quoteDB.addRecord(byteRec); } quoteDB.close(); }
The only other change required to have the ObtainQuoteSpotlet now work with the Palm OS database is to have the penDown method call the storePrice() method after the price, or in this case, the phony price, has been obtained.
if ((symbolField.getText().length() > 0) && (checkSymbol())) { Graphics.playSound(Graphics.SOUND_STARTUP); String sym = symbolField.getText().toUpperCase(); //later on, get the price from a quote service here int[] price = {75, 55}; Call to store the price quote when obtained storePrice(sym, price); resultsBox.setText("The price of " + sym + " is $" + price[0] + "." + price[1]); resultsBox.paint(); }
To see the KJava database wrapper in action, we go back to Jbed to rebuild our application. First make sure the ObtainQuote project is in use. Go to the Projects menu bar option and make sure the ObtainQuote project is checked. Next, open the ObtainQuoteSpotlet.java file by selecting the File menu bar option and selecting the Open menu item. After finding and selecting the ObtainQuoteSpotlet.java in the Open dialog box, add the code discussed previously to the Java program in the text editor. In particular, add the two new methods, storePrice() and getLastPrice(), 272
Copyright © OnBarcode.com . All rights reserved.