title: How to insert value into MySql table from user input JTextField
body: <p>I've tried to insert value into a table from user input in JTextField. The code runs with an error:</p>
  
  <blockquote>
    <p>You have an error in your SQL syntax; check the manual that
    corresponds to your MySQL server version for the right syntax</p>
  </blockquote>
  
  <p>Can anyone help me solve this problem? Thanks!</p>
  
  <p>Here is my code.</p>
  
  <pre><code>import java.awt.FlowLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.BorderLayout;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JTextField;
  
  class InputRoute
  {
  
  JTextField text1;
  JTextField text2;
  JTextField text3;
  String c;
  Float d;
  
  public void inputRoute() 
  {
  
      Connection conn = null;
      String url = "jdbc:mysql://localhost:3306/";
      String dbName = "YarraTram";
      String driver = "com.mysql.jdbc.Driver";
      String userName = "root";
      String password = "abc123";
  
      try 
      {
          Class.forName(driver).newInstance();
          conn = DriverManager.getConnection(url + dbName, userName, password);
  
          PreparedStatement statement = conn.prepareStatement("INSERT INTO  ('route', 'price') VALUES ('"+c+"', '"+d+"')");
          statement.executeQuery();
  
      } 
      catch (Exception e)
      {
          e.printStackTrace();
      }
  }
  
   public void createAndShowGUI() 
  {
  
      final JFrame frame = new JFrame("Yarra Tram Route Finder(New Route)");
  
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setLayout(new FlowLayout());
  
      JLabel label1 = new JLabel("From: ");
      JLabel label2 = new JLabel("To: ");
      JLabel label3 = new JLabel("Price: ");
  
      text1 = new JTextField(20);
      text2 = new JTextField(20);
      text3 = new JTextField(20);
  
      JButton button1 = new JButton("Add");
      JButton button2 = new JButton("Close");
  
      frame.add(label1, BorderLayout.WEST);
      frame.add(text1, BorderLayout.EAST);
      frame.add(label2, BorderLayout.WEST);
      frame.add(text2, BorderLayout.EAST);
      frame.add(label3, BorderLayout.WEST);
      frame.add(text3, BorderLayout.EAST);
      frame.add(button1);
      frame.add(button2);
  
      button2.addActionListener(new ActionListener() 
      {
          @Override
          public void actionPerformed(ActionEvent e) 
          {
              String a = text1.getText();
              String b = text2.getText();
              d = Float.parseFloat(text3.getText());
  
              c = a + " - " + b;
  
              inputRoute();
          }
      });
      button2.addActionListener(new ActionListener() 
      {
          @Override
          public void actionPerformed(ActionEvent e) 
          {
              frame.dispose();
          }
      });
  
      frame.setSize( 500,120 );
      frame.setLocationRelativeTo( null );
      frame.pack();
      frame.setVisible(true);
  } 
  }
  </code></pre>
  
  <p>Here is my MySQL table</p>
  
  <pre><code> CREATE TABLE `route` (
   `rid` int(11) NOT NULL AUTO_INCREMENT,
   `route` varchar(100) ,
   `price` decimal(5,2) ,
   PRIMARY KEY (`rid`)
   )
  </code></pre>