title: Select query using Prepared Statement
body: <p>I do not know what is wrong in my code. Following are the conditions in my code given below:</p>
  
  <ol>
  <li>I will enter the customer id in the jTextField</li>
  <li>After Entering the customer id then in the Database it will search relative information of that customer id (customer_id,customer_name,customer_contact).</li>
  <li>After Collecting relative information of that particular customer id, it will display on the jTextField.</li>
  </ol>
  
  <p>These is my code given below:</p>
  
  <pre><code>import java.awt.Container;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.sql.*;
  import javax.swing.*;
  
  public abstract class customer_details extends JFrame implements ActionListener
  {
  JTextField textFieldId;
  JTextField textFieldId1;
  JTextField textFieldId2;
  JTextField textFieldId3;    
  JLabel l1;
  JLabel l2;
  JLabel l3;
  JLabel l4;
  JLabel l5;
  JButton b1,b2;
  Container c = getContentPane();
  customer_details()
  {
      super("Shree Datta Digambar");
      setBounds(140,250,777,555);
      c.setLayout(null);
      textFieldId = new JTextField();        
      textFieldId1 = new JTextField();
      textFieldId2 = new JTextField();
      textFieldId3 = new JTextField();
      this.setExtendedState(JFrame.MAXIMIZED_BOTH);
      l1 = new JLabel("Update Customer Details:-");
      l2 = new JLabel("Customer Id");
      l3 = new JLabel("Customer Id");
      l4 = new JLabel("Name");
      l5 = new JLabel("Contact");
      l1.setBounds(10,10,340,20);
      l2.setBounds(10,20,140,70);
      l3.setBounds(10,100,140,70);
      l4.setBounds(100,100,140,70);
      l5.setBounds(270,100,140,70);
      textFieldId.setBounds(10,70,70,20);         
      textFieldId1.setBounds(10,160,70,20); 
      textFieldId2.setBounds(100,160,150,20); 
      textFieldId3.setBounds(270,160,90,20); 
      b1 = new JButton("Ok");
      b1.setBounds(100,70,50,20);   
      b2 = new JButton("Update");
      b2.setBounds(380,160,90,20);  
      c.add(b1);
      c.add(b2);
      c.add(l1);
      c.add(l2);
      c.add(l3);
      c.add(l4);
      c.add(l5);
      c.add(textFieldId);
      c.add(textFieldId1);
      c.add(textFieldId2);
      c.add(textFieldId3);       
      setVisible(true);
      setDefaultCloseOperation(EXIT_ON_CLOSE);                
      b1.addActionListener(this);               
      b2.addActionListener(this);
  }
  public static void main(String[] args) 
  {
      customer_details eeap=new customer_details() {};
  }
   public void actionPerformed(ActionEvent e)
  {               
      System.out.println("You clicked the button");             
      if(e.getSource()==b1)
      {
          try 
          {
              Connection con;                
              con = DriverManager.getConnection("jdbc:odbc:Dalvi");                                       
              java.sql.Statement st = con.createStatement();
              PreparedStatement ps = con.prepareStatement("SELECT customer_id,customer_name,customer_contact FROM customer_details WHERE customer_id = ?");                          
              ps.setString(1,textFieldId.getText());
              ResultSet rs1=ps.executeQuery();
              while(rs1.next())
              {                   
                  textFieldId1.setText(rs1.getString(1));
                  textFieldId2.setText(rs1.getString(2));
                  textFieldId3.setText(rs1.getString(3));   
              }                    
              textFieldId.setText("");
          }
          catch (SQLException s) 
          {
              System.out.println("SQL code does not execute.");
              JOptionPane.showMessageDialog(null,"Please Enter the Detail Correctly");
          }
      }  
  }
  </code></pre>
  
  <p>}</p>