title: Get data from TextField and insert into database with a click of a button
body: <p>I recently started coding and I am trying to create a Registration Form on Java but I can't get my &quot;Register&quot; button to get data from TextField and save it on my database.
  Here is what I have I am completely lost .</p>
  <pre><code>     Register.addActionListener(new ActionListener()
        {  
  public void actionPerformed(java.awt.event.ActionEvent e)
  {  if(fn.getText().equals(&quot;&quot;)||fn.getText()==null||ln.getText().equals(&quot;&quot;)||
     ln.getText()==null ||id.getText().equals(&quot;&quot;)||id.getText()==null ||gpa.getText().equals(&quot;&quot;)||gpa.getText()==null)
          JOptionPane.showMessageDialog(null, &quot;Please enter all Fields&quot;,&quot;Error&quot;,0);
       else{
          String First_Name=fn.getText();
          String Last_Name=ln.getText();
          String ID=id.getText();
          String GPA =gpa.getText();
         try{
             Connection connection=null;
             Connection conn=null;
             Class.forName(&quot;com.mysql.jdbc.Driver&quot;);
       conn=DriverManager.getConnection(&quot;jdbc:mysql://localhost:3306/MYDB&quot;,&quot;root&quot;,&quot;&quot;);         
       PreparedStatement pstmt = null;         
       String query = &quot;INSERT INTO CourseDemo(First_Name, Last_Name, ID, GPA)&quot; + &quot;VALUES (?, ?, ?, ?)&quot;;
       
       pstmt = conn.prepareCall(query);
        int status = pstmt.executeUpdate();
             if(status &gt; 0) {
              System.out.println(&quot;Record is inserted successfully !!!&quot;);
           }
         }
         catch(ClassNotFoundException ex){
             
         }            
         catch(Exception f){
           f.printStackTrace();
        }          
           
       }         
  }
        });
  </code></pre>