title: I need to enter my form data to databse but shows me a syntax error
body: <p>I need to enter my form data to databse but it shows me error called
  <strong>java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'groups,stdcount,hours)VALUES('1','DBS',' lalith ','Lecture','Y3S1G1','60','1am-3' at line 1</strong></p>
  <p>here is my code</p>
  <pre><code>PreparedStatement insert;
          
          String subName = jComboBox1.getSelectedItem( ).toString();
          String code = jTextField1.getText();
          String lecturersList = jList1.getSelectedValuesList().toString().replace(&quot;[&quot;, &quot; &quot;);
          String tag = jComboBox2.getSelectedItem().toString();
          String grpId = jComboBox3.getSelectedItem().toString();
          String stdQty = jTextField2.getText();
          String durations = jTextField3.getText();
          
          //new
  
          try {
              
              //Insert data to db           
              Class.forName(&quot;com.mysql.jdbc.Driver&quot;);
              conn = DriverManager.getConnection(DB_URL, username, password);
              insert = conn.prepareStatement(&quot;INSERT INTO session(subcode,subject,lecturers,tags,groups,stdcount,hours)VALUES(?,?,?,?,?,?,?)&quot;);
              
              insert.setString(3, lecturersList.toString().replace(&quot;]&quot;, &quot; &quot;));
              insert.setString(4, tag);
              insert.setString(5, grpId);
              insert.setString(2, subName);
              insert.setString(1, code);
              insert.setString(7, durations);
              insert.setString(6, stdQty);
              
              if(stdQty.isEmpty() || durations.isEmpty()){
                  JOptionPane.showMessageDialog(this, &quot;All Fields Required!&quot;);                
              }
              else{
                  
                  if(!(stdQty.matches(&quot;[0-9]+&quot;) || durations.matches(&quot;[0-9]+&quot;))){
                      JOptionPane.showMessageDialog(this, &quot;Should be Numbers!&quot;); 
                  }else{
                      
                      insert.executeUpdate();           
                      JOptionPane.showMessageDialog(this, &quot;Session Created!&quot;);
  
                      jTextField2.setText(&quot;&quot;);
                      jTextField3.setText(&quot;&quot;);
                      jTextField1.setText(&quot;&quot;);
                  }
              }                     
              
             
          } catch (ClassNotFoundException ex) {
              Logger.getLogger(AddSession.class.getName()).log(Level.SEVERE, null, ex);
          }catch (SQLException ex) {
              Logger.getLogger(AddSession.class.getName()).log(Level.SEVERE, null, ex);
          }
  </code></pre>