Home > Back-end >  Swing SQL server I want to obtain content from the text box to connect to the database, rather than
Swing SQL server I want to obtain content from the text box to connect to the database, rather than

Time:09-22

The import javax.mail. Swing. *;
Import the Java. The awt. *;
Import the Java. The awt. Event. *;
import java.sql.*;

Public class registered interface implements ActionListener {



Public void showFrame () {
JFrame fr=new JFrame ();
Fr. SetTitle (" registration screen ");
Fr. SetSize (335375);
Fr. SetDefaultCloseOperation (3);
Fr. SetLocationRelativeTo (null);
FlowLayout flow=new Java. The awt. FlowLayout ();
Fr. SetLayout (flow);

Javax.mail. Swing. ImageIcon image=new javax.mail. Swing. ImageIcon (" 2. JPG ");
Javax.mail. Swing. JLabel jla=new JLabel (image);
Java. The awt. Dimension dm1=new Dimension (400150);
Jla. SetPreferredSize (dm1);
Fr. Add (jla);

JLabel jla1=new JLabel (" account: ");
Fr. Add (jla1);

JTextField JTFD=new JTextField (12);
Dimension dm2=new Dimension (250, 30);
JTFD. SetPreferredSize (dm2);
Fr. Add (JTFD);

JLabel jla2=new JLabel (" password: ");
Fr. Add (jla2);

JPasswordField jtf1=new JPasswordField (6);
Dimension dm3=new Dimension (250, 30);
Jtf1. SetPreferredSize (dm3);
Fr. Add (jtf1);


JButton jbu=new javax.mail. Swing. JButton (" registration ");
Jbu. SetPreferredSize (dm2);
Fr. Add (jbu);

Jbu. AddActionListener (new ActionListener () {
Public void actionPerformed (an ActionEvent e) {
Fr. The dispose ();
The new login interface (). ShowFrame ();
}
});

Jbu. AddActionListener (this);
Fr. SetVisible (true);
}

Public void actionPerformed (an ActionEvent e) {
Try {

Class.forname (" com. Microsoft. Essentially. JDBC. SQLServerDriver ");
The String url="JDBC: essentially://localhost: 1433; DatabaseName=ABC ";
String userName="XZH";
String userPwd="xzh826268";
The Connection conn=DriverManager. GetConnection (url, userName, userPwd);
The Statement st.
St=conn. CreateStatement ();
St. executeUpdate (" insert into the operator (Id, PW) values (' lisi ', '123456') ");
conn.close();
}
The catch (Exception e1) {
JOptionPane. ShowMessageDialog (null, "password can only fill in six figures", "password error", JOptionPane. WARNING_MESSAGE);
}
}
}

CodePudding user response:

In the login button event handling input values, and then processing

CodePudding user response:

I joined in the event
String id=JTFD. GetText ();
String password=jtf1. GetText ();
Why can't get two the contents of a text box

CodePudding user response:

I joined in the event
String id=JTFD. GetText ();
Char [] pw=jtf1. GetPassword ();
String password=new String (pw);

Why can't get two the contents of a text box
  • Related