Using JDBC with Java Applications and Applets 92 (Web hosting and file sharing)
Using JDBC with Java Applications and Applets 92 Let s start with the insert query statement. As we already know, the insert command will allow a new row to be put into a database table. We want to expand our GUI program to allow the user to place an account number, username, and password in the appropriate text boxes and click a button to add the information to the table. Listing 5.3 shows the new code. In addition to the insert button, we have expanded the code to put SQL errors into a JTextArea. import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.sql.*; import java.util.*; public class Accounts extends JFrame { private JButton getAccountButton, insertAccountButton; private JList accountNumberList; private Connection connection; private JTextField accountIDText, usernameText, passwordText, tsText, activeTSText; private JTextArea errorText; public Accounts() { try { Class.forName(”com.mysql.jdbc.Driver”).newInstance(); } catch (Exception e) { System.err.println(”Unable to find and load driver”); System.exit(1); } } private void loadAccounts() { Vector v = new Vector(); try { Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery( “SELECT acc_id FROM acc_acc”); while(rs.next()) { v.addElement(rs.getString(”acc_id”)); } Listing 5.3 Our application for inserting a new row. (continues)
Note: If you are looking for best hosting provider to host and run your tomcat application check Astra tomcat hosting services