• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 569
  • Last Modified:

java - ms access

Need urgent help on small project.  I am having difficulty in getting my data to appear in the microsoft database.  The connection work finebut the data is not stored.  The code is given below please do not be concerned with other aspects of the code I will work on them myself but am only concerned with getting data to appear in the database.  APOLOGIES FOR THE MESS BUT WILL SORT OUT ONCE DATABASE PROBLEM HASBEEN RECTIFIED. Thankyou.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.*;
import java.util.*;
import java.sql.*;

import java.io.PrintStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class riskAnalyser extends JPanel
{
       // Variables declaration - do not modify
   private Connection connection;
         private Statement stmt;
      private String url="jdbc:odbc:fuzzy";
      private String username="zhussain";
      private String password="brutus";
      
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//String URL = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/fuzzy_loan_risk_analyser.MDB";
//DBConn = DriverManager.getConnection(URL,"","");

    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JCheckBox jCheckBox4;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox Age;
    private javax.swing.JComboBox JobHeld;
    private javax.swing.JComboBox Period;
    private javax.swing.JComboBox CreditRating;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField10;
    private javax.swing.JTextField Salary;
    private javax.swing.JTextField jTextField12;
    private javax.swing.JTextField jTextField13;
    private javax.swing.JTextField jTextField14;
    private javax.swing.JTextField jTextField15;
    private javax.swing.JTextField jTextField16;
    private javax.swing.JTextField Loan;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
   
    private String forename, surname, address1, address2, city, postcode, homeTel, mobTel, e_mail, occupation, salary, empName, empAdd1, empCity, empPostcode, empTelephone, amount;
    // End of variables declaration
   
    /** Creates new form JPanel */
    public riskAnalyser()
   
 
 {
        java.awt.GridBagConstraints gridBagConstraints;
try
            {
                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            }
            catch (Exception e)
            {
                    System.out.println("Failed to load JDBC/ODBC driver.");
                    return;
            }


            // get a connection
            try
            {
                    connection = DriverManager.getConnection(url, username, password);
                    System.out.println("Successful Connection To: " +url);
            }
            
            catch (Exception e)
            {
                    System.err.println("problems connecting to "+url);
            }
       
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jTextField7 = new javax.swing.JTextField();
        jTextField8 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jTextField9 = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        Age = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jTextField10 = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        JobHeld = new javax.swing.JComboBox();
        jLabel17 = new javax.swing.JLabel();
        Salary = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jTextField12 = new javax.swing.JTextField();
        jTextField13 = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        jTextField14 = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        jTextField15 = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        jTextField16 = new javax.swing.JTextField();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        Loan = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        Period = new javax.swing.JComboBox();
        jLabel28 = new javax.swing.JLabel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jLabel29 = new javax.swing.JLabel();
        jCheckBox3 = new javax.swing.JCheckBox();
        jCheckBox4 = new javax.swing.JCheckBox();
        jLabel30 = new javax.swing.JLabel();
        jLabel31 = new javax.swing.JLabel();
        CreditRating = new javax.swing.JComboBox();
        jButton2 = new javax.swing.JButton();
        jLabel32 = new javax.swing.JLabel();
        jLabel33 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();

        setLayout(new java.awt.GridBagLayout());
       

        setBackground(new java.awt.Color(194, 215, 240));
        setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(1, 1, 1, 1)));
        jLabel2.setText("Title");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new java.awt.Insets(9, 0, 9, 343);
        add(jLabel2, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        add(jLabel1, gridBagConstraints);

        jComboBox1.setBackground(new java.awt.Color(255, 255, 255));
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Mr", "Mrs", "Miss", "Ms" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new java.awt.Insets(9, 125, 0, 187);
        add(jComboBox1, gridBagConstraints);

        jLabel3.setText("*Surname");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.insets = new java.awt.Insets(15, 0, 0, 310);
        add(jLabel3, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 126;
        gridBagConstraints.insets = new java.awt.Insets(15, 125, 36, 112);
        add(jTextField1, gridBagConstraints);

        jLabel4.setText("Address 1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.insets = new java.awt.Insets(24, 2, 0, 307);
        add(jLabel4, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 126;
        gridBagConstraints.insets = new java.awt.Insets(24, 125, 36, 112);
        add(jTextField2, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 126;
        gridBagConstraints.insets = new java.awt.Insets(24, 73, 36, 52);
        add(jTextField3, gridBagConstraints);

        jLabel5.setText("Town/City");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.insets = new java.awt.Insets(24, 2, 0, 310);
        add(jLabel5, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 126;
        gridBagConstraints.insets = new java.awt.Insets(24, 125, 36, 112);
        add(jTextField4, gridBagConstraints);

        jLabel6.setText("*Postcode");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.insets = new java.awt.Insets(24, 325, 0, 106);
        add(jLabel6, gridBagConstraints);

        jTextField5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField5ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 126;
        gridBagConstraints.insets = new java.awt.Insets(24, 73, 36, 52);
        add(jTextField5, gridBagConstraints);

        jLabel7.setText("*Forename");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.insets = new java.awt.Insets(15, 325, 0, 103);
        add(jLabel7, gridBagConstraints);

        jTextField6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField6ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 126;
        gridBagConstraints.insets = new java.awt.Insets(15, 73, 36, 52);
        add(jTextField6, gridBagConstraints);

        jLabel8.setText("Telephone");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.insets = new java.awt.Insets(24, 2, 0, 306);
        add(jLabel8, gridBagConstraints);

        jLabel9.setText("Mobile");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.insets = new java.awt.Insets(24, 327, 0, 3);
        add(jLabel9, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 126;
        gridBagConstraints.insets = new java.awt.Insets(24, 125, 36, 112);
        add(jTextField7, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 126;
        gridBagConstraints.insets = new java.awt.Insets(24, 73, 36, 52);
        add(jTextField8, gridBagConstraints);

        jLabel10.setText("  E-Mail");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.insets = new java.awt.Insets(24, 0, 0, 327);
        add(jLabel10, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 126;
        gridBagConstraints.insets = new java.awt.Insets(24, 125, 41, 112);
        add(jTextField9, gridBagConstraints);

        jLabel11.setText("*Age");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.insets = new java.awt.Insets(24, 325, 0, 15);
        add(jLabel11, gridBagConstraints);

        Age.setBackground(new java.awt.Color(255, 255, 255));
        Age.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Select Age", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70" }));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 21;
        gridBagConstraints.insets = new java.awt.Insets(24, 73, 36, 10);
        add(Age, gridBagConstraints);

        jLabel12.setText("Address 2");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.insets = new java.awt.Insets(24, 327, 0, 105);
        add(jLabel12, gridBagConstraints);

        jLabel13.setFont(new java.awt.Font("Courier New", 1, 18));
        jLabel13.setForeground(new java.awt.Color(255, 51, 51));
        jLabel13.setText("Personal Details");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.ipadx = 4;
        gridBagConstraints.insets = new java.awt.Insets(60, 5, 0, 182);
        add(jLabel13, gridBagConstraints);

        jLabel14.setFont(new java.awt.Font("Courier New", 1, 18));
        jLabel14.setForeground(new java.awt.Color(255, 51, 51));
        jLabel14.setText("Employment ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 8;
        gridBagConstraints.ipadx = 79;
        gridBagConstraints.insets = new java.awt.Insets(24, 5, 0, 162);
        add(jLabel14, gridBagConstraints);

        jLabel15.setText("Occupation");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.insets = new java.awt.Insets(9, 2, 4, 300);
        add(jLabel15, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.ipadx = 126;
        gridBagConstraints.insets = new java.awt.Insets(9, 125, 0, 112);
        add(jTextField10, gridBagConstraints);

        jLabel16.setText("*Job Held");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.insets = new java.awt.Insets(9, 325, 4, 111);
        add(jLabel16, gridBagConstraints);

        JobHeld.setBackground(new java.awt.Color(255, 255, 255));
        JobHeld.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Years", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40" }));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 15;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.insets = new java.awt.Insets(9, 73, 39, 59);
        add(JobHeld, gridBagConstraints);

        jLabel17.setText("*Salary");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.insets = new java.awt.Insets(20, 0, 0, 326);
        add(jLabel17, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 10;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 116;
        gridBagConstraints.insets = new java.awt.Insets(20, 137, 40, 110);
        add(Salary, gridBagConstraints);


        jLabel19.setText("Employers Name");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 11;
        gridBagConstraints.ipady = 4;
        gridBagConstraints.insets = new java.awt.Insets(24, 2, 0, 269);
        add(jLabel19, gridBagConstraints);

        jLabel20.setText("Address");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 12;
        gridBagConstraints.insets = new java.awt.Insets(20, 2, 0, 317);
        add(jLabel20, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 12;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 126;
        gridBagConstraints.insets = new java.awt.Insets(20, 125, 36, 112);
        add(jTextField12, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 11;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.ipadx = 436;
        gridBagConstraints.insets = new java.awt.Insets(24, 125, 0, 57);
        add(jTextField13, gridBagConstraints);

        jLabel21.setText("Town/City");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 12;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.insets = new java.awt.Insets(20, 327, 0, 108);
        add(jLabel21, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 12;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 126;
        gridBagConstraints.insets = new java.awt.Insets(20, 73, 36, 52);
        add(jTextField14, gridBagConstraints);

        jLabel22.setText("Postcode");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 13;
        gridBagConstraints.insets = new java.awt.Insets(24, 2, 0, 311);
        add(jLabel22, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 13;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 126;
        gridBagConstraints.insets = new java.awt.Insets(24, 125, 41, 112);
        add(jTextField15, gridBagConstraints);

        jLabel23.setText("Telephone");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 13;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.insets = new java.awt.Insets(24, 327, 0, 104);
        add(jLabel23, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 13;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 126;
        gridBagConstraints.insets = new java.awt.Insets(24, 73, 41, 52);
        add(jTextField16, gridBagConstraints);

        jLabel24.setFont(new java.awt.Font("Courier New", 1, 18));
        jLabel24.setForeground(new java.awt.Color(255, 51, 51));
        jLabel24.setText("Loan Details");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 14;
        gridBagConstraints.insets = new java.awt.Insets(24, 5, 0, 230);
        add(jLabel24, gridBagConstraints);

        jLabel25.setText("*Amount Required");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 15;
        gridBagConstraints.insets = new java.awt.Insets(9, 0, 0, 264);
        add(jLabel25, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 15;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 116;
        gridBagConstraints.insets = new java.awt.Insets(9, 137, 44, 110);
        add(Loan, gridBagConstraints);

 

        jLabel27.setText("*Period");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 15;
        gridBagConstraints.insets = new java.awt.Insets(9, 325, 0, 0);
        add(jLabel27, gridBagConstraints);

        Period.setBackground(new java.awt.Color(255, 255, 255));
        Period.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Years", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" }));
        Period.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PeriodActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.insets = new java.awt.Insets(4, 73, 0, 59);
        add(Period, gridBagConstraints);

        jLabel28.setText("Have you had a loan declined in the past?");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 16;
        gridBagConstraints.insets = new java.awt.Insets(24, 5, 8, 130);
        add(jLabel28, gridBagConstraints);

        jCheckBox1.setBackground(new java.awt.Color(255, 255, 255));
        jCheckBox1.setText("Yes");
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 16;
        gridBagConstraints.ipadx = 4;
        gridBagConstraints.insets = new java.awt.Insets(24, 73, 0, 0);
        add(jCheckBox1, gridBagConstraints);

        jCheckBox2.setBackground(new java.awt.Color(255, 255, 255));
        jCheckBox2.setText("No");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 16;
        gridBagConstraints.insets = new java.awt.Insets(24, 30, 0, 0);
        add(jCheckBox2, gridBagConstraints);

        jLabel29.setText("Have you been clear of CCJs and Arrears in the last 12 months?");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 17;
        gridBagConstraints.insets = new java.awt.Insets(6, 5, 8, 2);
        add(jLabel29, gridBagConstraints);

        jCheckBox3.setBackground(new java.awt.Color(255, 255, 255));
        jCheckBox3.setText("Yes");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 17;
        gridBagConstraints.ipadx = 4;
        gridBagConstraints.insets = new java.awt.Insets(6, 73, 0, 0);
        add(jCheckBox3, gridBagConstraints);

        jCheckBox4.setBackground(new java.awt.Color(255, 255, 255));
        jCheckBox4.setText("No");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 17;
        gridBagConstraints.insets = new java.awt.Insets(6, 30, 0, 0);
        add(jCheckBox4, gridBagConstraints);

        jLabel30.setFont(new java.awt.Font("Courier New", 1, 18));
        jLabel30.setForeground(new java.awt.Color(255, 51, 51));
        jLabel30.setText("Staff");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 18;
        gridBagConstraints.ipadx = 35;
        gridBagConstraints.insets = new java.awt.Insets(16, 2, 0, 275);
        add(jLabel30, gridBagConstraints);

        jLabel31.setText("*Credit Rating");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 19;
        gridBagConstraints.insets = new java.awt.Insets(9, 0, 25, 289);
        add(jLabel31, gridBagConstraints);

        CreditRating.setBackground(new java.awt.Color(255, 255, 255));
        CreditRating.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Select", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 19;
        gridBagConstraints.ipady = -5;
        gridBagConstraints.insets = new java.awt.Insets(9, 137, 21, 166);
        add(CreditRating, gridBagConstraints);

        jButton2.setBackground(new java.awt.Color(241, 249, 201));
        jButton2.setText("Submit");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 19;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.ipadx = 26;
        gridBagConstraints.insets = new java.awt.Insets(24, 8, 0, 24);
        add(jButton2, gridBagConstraints);

            
       
        jLabel32.setFont(new java.awt.Font("Arial Black", 1, 24));
        jLabel32.setIcon(new javax.swing.ImageIcon("Z:\\fyp\\Untitled-6 copy.jpg"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.ipady = -130;
        gridBagConstraints.insets = new java.awt.Insets(0, 95, 1, 65);
        add(jLabel32, gridBagConstraints);

        jLabel33.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel33.setForeground(new java.awt.Color(255, 51, 51));
        jLabel33.setText("* Denotes compulsory feilds");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 19;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.insets = new java.awt.Insets(39, 5, 19, 203);
        add(jLabel33, gridBagConstraints);

        jButton3.setBackground(new java.awt.Color(241, 249, 201));
        jButton3.setText("Save");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
       
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 19;
        gridBagConstraints.ipadx = 36;
        gridBagConstraints.insets = new java.awt.Insets(24, 21, 0, 2);
        add(jButton3, gridBagConstraints);

        jButton4.setBackground(new java.awt.Color(241, 249, 201));
        jButton4.setText("Quit");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 19;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.ipadx = 43;
        gridBagConstraints.insets = new java.awt.Insets(24, 278, 0, 112);
        add(jButton4, gridBagConstraints);

    }

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {

                  
                  System.exit( 0 );
                        // Add your handling code here:
    }

    private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) {
        // Add your handling code here:
    }

    private void PeriodActionPerformed(java.awt.event.ActionEvent evt) {
        // Add your handling code here:
    }

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
          
                        JOptionPane.showMessageDialog (null,"Thankyou, Your Details Have Been Successfully Saved.","",JOptionPane.INFORMATION_MESSAGE);
                        PrintWriter outputStream = null;
                  try
                        {
                        // Gets the booking number from the textfield to use as the file name
                        String a = jTextField6.getText();
                        outputStream = new PrintWriter(new FileOutputStream(" " + a +".csv"));
                        outputStream.println("Age, Loan, Period,  Salary, JobHeld, CreditRating");
                        outputStream.println(" "  + Age.getSelectedItem() + "," +" " +
                        Loan.getText() + ","+  " " +
                        Period.getSelectedItem() + "," + " "+
                        Salary.getText() + "," + " "+
                        JobHeld.getSelectedItem() + "," + " " +
                        CreditRating.getSelectedItem());
                  
                        
                        outputStream.close();
                        System.out.println("... written to output file");
                        }

                        catch(IOException ioException)
                        {
                        System.out.println("Error");
                        }

                  }


        // Add your handling code here:
   
      private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
            
            String title = (String)jComboBox1.getSelectedItem();
            surname = jTextField1.getText();
            forename = jTextField6.getText();
            address1 = jTextField2.getText();
            address2 =      jTextField3.getText();
            city =      jTextField4.getText();
            postcode = jTextField5.getText();
            homeTel = jTextField7.getText();
            mobTel = jTextField8.getText();
            e_mail = jTextField9.getText();
            String age = (String)Age.getSelectedItem();
            occupation = jTextField3.getText();
            salary = Salary.getText();
            String jobHeld = (String)JobHeld.getSelectedItem();
            empName = jTextField12.getText();
            empAdd1      = jTextField13.getText();
            empCity = jTextField14.getText();
            empPostcode = jTextField15.getText();
            empTelephone      = jTextField16.getText();
            amount = Loan.getText();
            String period= (String)Period.getSelectedItem();
            String creditRating = (String)CreditRating.getSelectedItem();
            
            String addDataSql;
        addDataSql = "INSERT INTO Customer (Title, Forename, Surname, Address1, Address2, City, Postcode, HomeTel, MobTel, E-Mail, Age, Occupation, Salary, JobHeld, EmpName, EmpAdd1, EmpCity, EmpPostcode, EmpTelephone, Amount, Period, CreditRating, Decision ) VALUES ('"+title+"','"+forename+"', '"+surname+"', '"+address1+"', '"+address2+"', '"+city+"',"+postcode+"', '"+homeTel+"', '"+mobTel+"', '"+e_mail+"', '"+age+"', '"+occupation+"', '"+salary+"', '"+jobHeld+"', '"+empName+"', '"+empAdd1+"', '"+empCity+"', '"+empPostcode+"', '"+empTelephone+"', '"+amount+"', '"+period+"', '"+creditRating+"', ' " +"   "+  "')";
              addData(addDataSql);
        
                                                               
                        removeAll();
                        add(new riskAnalyser());
                        validate();
            }
     
      
   
    private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {
        // Add your handling code here:
    }

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
        // Add your handling code here:
    }

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {
        // Add your handling code here:
    }
   
   
   
    public void addData(String sql)
      {
      
            try
            {
                        stmt = connection.createStatement();
                  
                        System.out.println(sql);
                          
                          stmt.executeUpdate(sql);
                        System.out.println("Data Input Successful");
                        JOptionPane.showMessageDialog(null, "Customer Created Successfully");

                                            
                  
            }
            catch(SQLException undex)
            {
                  System.out.println("Customer Database Not Updated");
                  JOptionPane.showMessageDialog(null, "Customer NOT Created. \nThis may be because either an invalid entry was entered in one of the input text fields or you did not input data in all the text fields. Please try agian.");
            }
         }
         


public static void main(String[] args)
      {
      JFrame frame = new JFrame("Risk Analysis System");
      frame.addWindowListener(new WindowAdapter()
            {
          public void windowClosing(WindowEvent e)
                  {
                  System.exit(0);
                  }
            });
      frame.getContentPane().add(new riskAnalyser(), BorderLayout.CENTER);
      frame.setSize(800, 850);
      frame.setVisible(true);
      }
}
0
zhussai7
Asked:
zhussai7
1 Solution
 
VosJCommented:
I started to check your SQL-statement (INSERT INTO) in ms-acces and I received 3 sql-errors.

1. The word E-mail is not excepted in acces is considered as 2 words, 2 or more words need to be enclosed by [] in the sql-statement
2. The quotes on both sides of postcode are wrong.
3. And the ) at the end of the sql-statement has to be without quotes.

Jan
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Also - every driver does not allow you to insert using executeUpdate (). Try using execute () or using PreparedStatement.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now