Buttons and menu items

An SQLStatementButton object represents a button that issues an SQL (Structured Query Language) statement when pressed. The SQLStatementButton class extends the Java™ Foundation Classes (JFC) JButton class so that all buttons have a consistent appearance and behavior.

Similarly, an SQLStatementMenuItem object represents a menu item that issues an SQL statement when selected. The SQLStatementMenuItem class extends the JFC JMenuItem class so that all menu items have a consistent appearance and behavior.

To use either of these classes, set both the connection and the SQLStatement properties. These properties can be set using a constructor or the setConnection() and setSQLStatement() methods.

The following example creates an SQLStatementButton. When the button is pressed at run time, it deletes all records in a table:

                       // Create an SQLStatementButton object.
                       // The button text says "Delete All",
                       // and there is no icon.
     SQLStatementButton button = new SQLStatementButton ("Delete All");

                       // Set the connection and SQLStatement
                       // properties.  Assume that "connection"
                       // is an SQLConnection object that is
                       // created and initialized elsewhere.  
     button.setConnection (connection);
     button.setSQLStatement ("DELETE FROM MYTABLE");
            
                       // Add the button to a frame. Assume
                       // that "frame" is a JFrame created
                       // elsewhere.
     frame.getContentPane ().add (button);

After the SQL statement is issued, use getResultSet(), getMoreResults(), getUpdateCount(), or getWarnings() to retrieve the results.