title: Why am I not able to add user input into database with front end as java and back end as mysql?
body: <p>create table query for department :
  create table department 
  (
  department_id tinyint(2) zerofill not null auto_increment,
  department_name varchar(30) unique key,
  department_description text,
  primary key(department_id)
  );</p>
  
  <p>java code:
      package hrmps;</p>
  
  <pre><code>import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import javax.swing.*;
  
  class AddDepartment extends JPanel
  {
  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
  {                                         
  String deptName=jTextField1.getText();
  String deptDescription=jTextField2.getText();
  
  Connection con=null;
  PreparedStatement statement=null;
  ResultSet rs=null;
  
  String query="Insert into department values (?,?)";
  
  
               try
               {
                    Class.forName("com.mysql.jdbc.Driver");
                  con=DriverManager.getConnection("jdbc:mysql:///hrmps?               zeroDateTimeBehavior=convertToNull","root","root");
                  statement=con.prepareStatement(query);
                  statement.setString(1,deptName);
                  statement.setString(2,deptDescription);
                  statement.execute();
  
                  int i=statement.executeUpdate();
  
                  if(i&gt;0)
  
                       JOptionPane.showMessageDialog(null, "Record added");
  
  
                  else
  
                          JOptionPane.showMessageDialog(null, "Record couldn't     be added");
  
  
                  con.close();
            }
  
          catch(Exception ex)
          {
              System.out.println(ex.getMessage());
          }
  
  
  }         //end of method                               
  </code></pre>
  
  <p>}//end of class</p>