Developing SQL Server based Java Apps using NetBeans IDE
This article introduces you to developing Java (or JFC) based applications with Microsoft SQL Server as the database, using NetBeans IDE. In this first article in a series, I will show you how to establish a connection from your Java programs to a Microsoft SQL Server database using JDBC.
Developing SQL Server based Java Apps using NetBeans IDE - Creating a Microsoft SQL Server database connection using NetBeans IDE: Form Design (Page 5 of 6 )
In this section, instead of simply connecting to Microsoft SQL Server, I shall go a bit further to give us the number of rows available in a table. This would be much more practical.
We shall develop a small application with a button, ScrollPane and TextArea. When the button is hit, it needs to give out the number of rows available. I named the project “SampleJavaApplication1” and the form (or JFrame) as “DBSample01” in the package “MyDBPack.”
When the form (or JFrame) is created with “DBSample01,” the code behind it (only the constructor) would look something like the following:
public class DBSample01 extends javax.swing.JFrame {
/** Creates new form DBSample01 */ public DBSample01() { initComponents(); }
Make changes to the above code fragment in such a way that it looks similar to the following:
public class DBSample01 extends javax.swing.JFrame {
/** Creates new form DBSample01 */ public DBSample01() { initComponents(); this.setSize(300,200); }
In the above code, I explicitly defined the initial size of the frame. Before dropping all controls on the form, set the layout to “null layout” (fig 02) to ease our development for this article. When you complete your form design, it should look something like fig 2, and the “inspector” view should look something like fig 2-1.
Figure 02."null layout".
Figure 02-1."inspector" view.
For the convenience of writing understandable code, I named those controls as follows:
tbtnBold tbtnItalic txtMsg
I also gave a value to the Frame property “title” (using the property window), namely “ToggleButtons: a Demo.”