Using JDBC with Java Applications and Applets 88 (Hsphere web hosting)

Using JDBC with Java Applications and Applets 88 show(); } public void connectToDB() { try { connection = DriverManager.getConnection( “jdbc:mysql://localhost/accounts”); } catch(SQLException e) { System.out.println(”Unable to connect to database”); System.exit(1); } } private void displaySQLErrors(SQLException e) { System.out.println(”SQLException: ” + e.getMessage()); System.out.println(”SQLState: ” + e.getSQLState()); System.out.println(”VendorError: ” + e.getErrorCode()); } private void init() { connectToDB(); } public static void main(String[] args) { Accounts accounts = new Accounts(); accounts.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); accounts.init(); accounts.buildGUI(); } } Listing 5.2 Our GUI application. (continued) The code in Listing 5.2 is designed to illustrate using MySQL and a Java GUI application. Figure 5.3 shows what the GUI looks like when it is first executed. We ve broken down the code into a series of methods, which we discuss next. Our Main Function Just as in any Java application, our main function instantiates an object of our class type. Notice that our class extends JFrame because we need to provide a GUI with the application. When the object s constructor is called, the Connec
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services

Comments are closed.