title: how to save data to database from JCombobox and JTextarea in eclipse juno
body: <p>I'm using eclipse Juno to write my code. I would like to input my data to database but when I click the save button I got error on JTextarea and JCombobox.</p>
  
  <p>Here's the error:</p>
  
  <blockquote>
    <p>Cannot refer to a non-final variable textALAMAT inside an inner class
    defined in a different method Cannot refer to a non-final variable
    cbJURUSAN inside an inner class defined in a different method</p>
  </blockquote>
  
  <p>and here's my code:</p>
  
  <pre><code>    JScrollPane scrollPane = new JScrollPane();
      scrollPane.setBounds(35, 282, 475, 106);
      contentPane.add(scrollPane);
  
      tabelmodel = new DefaultTableModel(null,header);
      tabel = new JTable();
      tabel.setModel(tabelmodel);
      scrollPane.setViewportView(tabel);
  
      JLabel lblNim = new JLabel("NIM");
      lblNim.setBounds(35, 24, 46, 14);
      contentPane.add(lblNim);
  
      JLabel lblNama = new JLabel("NAMA");
      lblNama.setBounds(35, 59, 46, 14);
      contentPane.add(lblNama);
  
      JLabel lblJurusan = new JLabel("JURUSAN");
      lblJurusan.setBounds(35, 97, 46, 14);
      contentPane.add(lblJurusan);
  
      JLabel lblAlamat = new JLabel("ALAMAT");
      lblAlamat.setBounds(35, 138, 46, 14);
      contentPane.add(lblAlamat);
  
      textNIM = new JTextField();
      textNIM.setBounds(119, 18, 230, 27);
      contentPane.add(textNIM);
      textNIM.setColumns(10);
  
      textNAMA = new JTextField();
      textNAMA.setColumns(10);
      textNAMA.setBounds(119, 53, 230, 27);
      contentPane.add(textNAMA);
  
      JComboBox cbJURUSAN = new JComboBox();
      cbJURUSAN.setModel(new DefaultComboBoxModel(new String[] {"Teknik Informatika", "Teknik Komputer", "Sistem Informasi", "Sastra Inggris"}));
      cbJURUSAN.setBounds(118, 91, 231, 27);
      contentPane.add(cbJURUSAN);
  
      final JTextArea textALAMAT = new JTextArea();
      textALAMAT.setBounds(119, 133, 354, 90);
      contentPane.add(textALAMAT);
  
      JButton btnSave = new JButton("SAVE");
      btnSimpan.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent arg0)
          {
              String jurusan = "";
              if(cbJURUSAN.getSelectedIndex() == 0)
              {
              jurusan = "Teknik Informatika";
              } 
              else if(cbJURUSAN.getSelectedIndex() == 1)
              {
              jurusan = "Teknik Komputer";
              } 
              else if(cbJURUSAN.getSelectedIndex() == 2)
              {
              jurusan = "Sistem Informasi";
              }
              else if(cbJURUSAN.getSelectedIndex() == 3)
              {
              jurusan = "Sastra Inggris";
              } 
              try
              {
                  Connection konek = koneksi.getKoneksi();
                  String query = "INSERT INTO mahasiswa VALUES (?,?,?,?)";
                  PreparedStatement prepare = konek.prepareStatement(query);
                  prepare.setInt(1,Integer.parseInt(textNIM.getText()));
                  prepare.setString(2, textNAMA.getText());
                  prepare.setString(3, jurusan);
                  prepare.setString(4, textALAMAT.getText());
                  prepare.executeUpdate();
                  JOptionPane.showMessageDialog(null,"Data berhasil ditambahkan ke database");
              } 
              catch (Exception ex)
              {
                  JOptionPane.showMessageDialog(null,"Data gagal ditambahkan ke database");
                  System.out.println(ex);
              }
              finally
              {
                  getDataTable();
              }
          }
      });
      btnSave.setBounds(49, 248, 89, 23);
      contentPane.add(btnSimpan);
  </code></pre>
  
  <p>Can anybody help me to solve this?</p>