Apr 30

When processing a large file (for example using ‘LOAD DATA LOCAL INFILE’) the connection to mysql can get lost. Reason for this is the mysql server has a limit on the size of a ‘packet’ it receives and when this limit is exceeded it drops the connection.

This limit can be changed using the system variable max_allowed_packet. This specifies the maximum size of a packet in bytes.

A packet is a single SQL statement sent to the MySQL server, a single row that is sent to the client, or a binary log event sent from a master replication server to a slave.

written by objects \\ tags: ,

Apr 28

By default components added to a JToolBar will be left aligned. Often we want to shift some item to the right (for example a Help button is often displayed to the right).

The JToolBar uses a BoxLayout to layout it’s components. This allows us to simply add some ‘glue’ to push subsequently added components to the right.

JToolBar toolbar = new JToolBar();

// These buttons will be left aligned by default

toolbar.add(new JButton("Open"));
toolbar.add(new JButton("Save"));

// add some glue so subsequent items are pushed to the right

toolbar.add(Box.createHorizontalGlue());

// This Help button will be right aligned

toolbar.add(new JButton("Help"));

written by objects \\ tags: , , ,

Apr 15

public static String zeroPad(int value, int width) {
   return String.format("%0"+width+"d", value);
}

written by objects \\ tags: , , ,