title: Show MySQL data to JTextField
body: <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.sql.*;
  
  public class RegistrationForm extends JFrame {
      
      private JPanel panel;
      private JLabel user,pass,id;
      private JTextField user1,pass1,id1;
      private JButton save,signIn;
      public Connection con; 
      public Statement stm; 
      public PreparedStatement pstm;
      
      public RegistrationForm(){
          setTitle("Register Account");
          setLayout(new FlowLayout());
  
          setContentPane(new JLabel(new ImageIcon("C:\\Users\\RenRen\\Documents\\NetBeansProjects\\JavaConnector\\src\\images\\reg.jpg")));
          
          JLabel sign = new JLabel("Sign Up:");
          sign.setBounds(100,95,80,30);
          sign.setFont(new Font("Login",Font.ITALIC,20));
          
          
          id= new JLabel("User ID");  
          user = new JLabel("Username:");
          pass = new JLabel("Password:");
          JLabel acc = new JLabel("Already have an Account?");
          
          id.setBounds(300,95,80,30);
          user.setBounds(130,140,80,20);
          pass.setBounds(250,140,80,20);
          acc.setBounds(250,230,150,20);
          
          id1 = new JTextField(5);
          user1 = new JTextField(10);
          pass1 = new JPasswordField(10);
          
          id1.setBounds(350,100,80,20);
          user1.setBounds(130,160,110,20);
          pass1.setBounds(250,160,110,20);
          
          save = new JButton("Save");
          signIn = new JButton("Sign In");
          
          save.setBounds(150,200,90,20);
          signIn.setBounds(250,200,90,20);
          
          add(sign);
          add(id);
          add(id1);
         add(user);
          add(user1);
          add(pass);
          add(pass1);
          add(save);
          add(signIn);
         add(acc);
          
         try 
  { 
  Class.forName("com.mysql.jdbc.Driver"); 
  con=DriverManager.getConnection("jdbc:mysql://localhost:3306/login","root",""); 
  stm=con.createStatement();
  } 
  catch(Exception e) 
  { JOptionPane.showMessageDialog(null, e);
  } 
           ActionListener action = new ActionHandler();  
          save.addActionListener(action); 
          
          signIn.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                    //JOptionPane.showMessageDialog(null, "Thank You!");
                  dispose();
                  LoginMain LM = new LoginMain();
                  LM.run();
              }});
                 
   
          
          
          }
      private class ActionHandler implements ActionListener{
  
          @Override
          public void actionPerformed(ActionEvent e) {
              
              Object source = e.getSource();
              if(source == save){
              String sql="Insert into logform(username,password)values(?,?)";
              try{
                  pstm = con.prepareStatement(sql);
                  pstm.setString(1, user1.getText());
                  pstm.setString(2, pass1.getText());
                  
                  pstm.execute();
                  JOptionPane.showMessageDialog(null, "Saved!");
              }catch(Exception se){
                 JOptionPane.showMessageDialog(null, "Save Failed");
              }
              }
          }        
      }
  
        public void run(){ 
          
            setSize(500,300);
          setLocationRelativeTo(null);
          setVisible(true);
          setResizable(false);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      }
        
        
             public static void main(String[] args){
              
              RegistrationForm rf = new RegistrationForm();
              rf.run();
          }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>I want to show a data from MySQL database to JTextField. For example, a data from UserID in MySQL database is 1, I want to show that data in JTextField, and they can't edit text in JTextField. <BR/><BR/>Can anyone help me please?</p>