Tuesday, October 30, 2007

Format your Code for Blogger

Finally, I found a solution of how to easily format my Source Code examples for Blogger. I've seen many examples of how other blog services handle this, such as Wordpress, but I don't use Wordpress...

Here is how to easily do this, until Blogger comes up with an easier way:

Copy your source code example and paste it into this page:

Source Code Formatter for Blogger

Click on the "Format Code" button and copy the results.

Switch to "Edit Html" view in your Blogger Edit Post page and paste in the formatted code example.

Here is what a sample PL/SQL example would looks like:

FOR cur IN (select id from test)
UPDATE table SET column = "DONE" WHERE id = cur.id where;

Thanks to Greg Houston for this simple solution.

Friday, October 26, 2007

How to Use JList - for Dummies

I've built a few Java programs and am still not proficient with my tools, so I am laying out a series of simple instructions for learning and using the basic Java Swing tools. This will reference the websites where I go for direction as well as examples that I've found useful.

The first place I always start is the Java tutorials on using Swing:

How to Use Lists

I ran into a situation where I had to remove multiple elements from a JList. Here is the exact trick on how to do that. It worked perfectly:

Remove Multiple Items from a List

Thursday, October 25, 2007

Percentage of Americans who do not fill out a Change of Address with USPS

Here is an excerpt giving an estimate of how many Americans move each year that do not fill out a change of address request with the post office. These address changes would not be returned with NCOA and would require other means of address recovery such as a "Deluxe" NCOA service that utilizes other address change databases such as magazine subscription lists, utility company databases and even the "Pizza Hut" database they maintain of deliveries they've made and address changes they've maintained.

One of the fallacies surrounding consumer list compilation is that the U. S. Postal Service’s National Change of Address file is the answer to this problem. The fact is, however, that NCOA, while helpful, falls far short of the accuracy that most of us would prefer. An estimated 30 percent of the people who move in the United States never file a change-of-address form with the postal service. And even when they do, it is sometimes weeks or even months before that information is made available to list compilers or the direct marketers who use the lists.

Competent list managers have created routines that address this problem. For example, if there is a change of address on a current, reliable source (such as new billing addresses for a charge account or new utility hookups) the new address might be placed in the consumer record. This type of effort can significantly improve address quality on a mailing list – but it cannot ever be perfect.

Wednesday, October 24, 2007

Jlist or Jtable - I need a multi-column display

I'm gradually coming to grips with programming user interfaces in Java. Read a bit on the MVC (Model View Control) concept and while I see its value, it is a bit too steep a gradient at this point. I am starting off getting the basics of the Swing GUI and have been using Jgoodies with the Jigloo Windows builder. Even that is a bit steep as I want to know how to build these from the ground up and using the drag and drop tools resulted in skipping some of the basics that left me hanging, when trying to modify and customize what Jigloo provide.d

What has helped learn this the fastest has been to work out some simple application that will be useful and then laying out a UML diagram including Use Case for the requirements, Activity Diagrams and Class Diagrams. A programmer is lost in the woods without these design tools. Then I've taken one element at a time, the JDBC database access, pulling up a list and displaying this, etc.

I am up to a point where I need to display a simple list of entries from a database. The list should have 3 columns. I've only been able to get this to work with one column so far. So what I am looking into is whether it would be better to just use the JTable or figure out a "multi-column" JList.

Here are some resources to figure this out:

Code Guru
Java Sun
Dream In Code
Jlist Tutorial

One simple method of doing this would be to select your multi-column data from your data source and return this resultset to a String array.

Refresh a JTable from a JDBC connection

I have a Swing application that uses a JTable and JScrollPane to display data from an Access database via a JDBC connection.

Even though I had properly coded the SQL INSERT statement and the data was loading into my database, the JTable was not refreshing with the new record. I tried the .revalidate() and the .repaint() methods to no avail.

Finally, after reading Ben Hendry's Mastering JTable I was able to sort this out.

In my JButton ActionListener I added the TableModel.addRow method and inserted the newly inserted records into the JTable as well. Followed by a .revalidate() and the data properly displayed without even a flicker in my application.

Moral of the story - always use Model-View-Control (MVC) architecture and separate your view from your data and controls.