Home > other >  The Java connection mysql times null pointer exception
The Java connection mysql times null pointer exception

Time:03-25

Before I use Java connection used, can the connection is successful, and can add and delete, now want to switch to mysql database, to replace the corresponding jar, connection command also slightly modified, the display can be connected to success, but in the query authentication login has been submitted to the null pointer exception, said red mark is a problem with the SQL statements below, also please help to have a look at
Login interface code and operation interface is as follows:

/*
* function: books management system management system
* step 1: login interface static implementation
Step 2: add to the various components of listening,
* step 3: to authenticate a user name and password,
* the author: paranoidyang
*/
Package the login;

The import javax.mail. Swing. *;

The import home. Home;
The import utils. Mysql;
The import utils. Utils;

Import the Java. The awt. *;
Import the Java. The awt. Event. An ActionEvent;
Import the Java. The awt. Event. ActionListener;

Public class Login extends JFrame implements ActionListener {

//define components

JPanel jp1, jp2, jp3, jp4=null;
The static JTextField userName_jtf=null;
The static JPasswordField password_jtf=null;

Private JLabel logoLabel, userNameLabel passwordLabel;
Private JButton login_btn reset_btn;

Public static void main (String [] args) {
//TODO Auto - generated method stub
The new Login ();
}

Public the Login () {

The Container Container=this. GetContentPane ();
Enclosing setLayout (null);//

//create the tag
LogoLabel=new JLabel (" books management system management system ");
LogoLabel. SetIcon (new ImageIcon (enclosing getClass () getClassLoader (). The getResource (" images/logo. PNG ")));
LogoLabel. SetFont (Utils. F1);//utils to is a utility class for custom a font class
LogoLabel. SetBounds (150, 50, 200, 40).
The container. The add (logoLabel);
//create a user name tag
UserNameLabel=new JLabel (" user name: ");
UserNameLabel. SetIcon (new ImageIcon (enclosing getClass () getClassLoader (). The getResource (" images/user. PNG ")));
UserNameLabel. SetFont (Utils. F2);
UserNameLabel. SetBounds (120, 140, 80, 40).
The container. The add (userNameLabel);
//create a user name input box
UserName_jtf=new JTextField (10);
UserName_jtf. SetBounds (220, 148, 150, 20).
The container. The add (userName_jtf);
//create password tag
PasswordLabel=new JLabel (" password: ");
PasswordLabel. SetIcon (new ImageIcon (enclosing getClass () getClassLoader (). The getResource (" images/password. PNG ")));
PasswordLabel. SetFont (Utils. F2);
PasswordLabel. SetBounds (120, 180, 80, 40).
The container. The add (passwordLabel);
//create the password input box
Password_jtf=new JPasswordField (10);
Password_jtf. SetBounds (220, 188, 150, 20).
The container. The add (password_jtf);

//create the login button
Login_btn=new JButton (" login ");
Login_btn. SetFont (Utils. F2);
Login_btn. SetIcon (new ImageIcon (enclosing getClass () getClassLoader (). The getResource (" images/login. PNG ")));
Login_btn. SetBounds (100, 260, 90, 30);
The container. The add (login_btn);

//create the reset button
Reset_btn=new JButton (" reset ");
Reset_btn. SetFont (Utils. F2);
Reset_btn. SetIcon (new ImageIcon (enclosing getClass () getClassLoader (). The getResource (" images/reset. PNG ")));
Reset_btn. SetBounds (300, 260, 90, 30);
The container. The add (reset_btn);

//set button to monitor
Login_btn. AddActionListener (this);
Reset_btn. AddActionListener (this);

//to window set title
Enclosing setTitle (" books management system management system ");
Enclosing setIconImage (new ImageIcon (enclosing getClass () getClassLoader (). The getResource (" images/tittle. PNG ")). The getImage ());

//set to form an irreversible size
Enclosing setResizable (false);
//set the form size
Enclosing setSize (500, 400);
/*
* implementation form shown in the bureau, why no effect?
* must be in after setting the window size calls to display in the middle, otherwise will be displayed in the lower right corner, the parameter is null, the method is to form the center moved to the middle of the screen, if not the size of the specified form at the beginning, that is a point,
* call this function at this time, be equivalent to move form in the upper left corner to the middle, and then on this basis to add other components, make the form gets bigger, so is displayed in the lower right
*/
Enclosing setLocationRelativeTo (null);
//set when the window is closed, to guarantee the JVM also exit
Enclosing setDefaultCloseOperation (JFrame. EXIT_ON_CLOSE);
//show the form
Enclosing setVisible (true);
}

@ Override
Public void actionPerformed (an ActionEvent e) {

If (um participant etActionCommand ()=="login") {
//connect to the database to check user name and password
if (! UserName_jtf. GetText (). The isEmpty () & amp; & ! Password_jtf. GetText (). The isEmpty ()) {

Enclosing uselogin ();

} else if (userName_jtf getText (). The isEmpty ()) {

JOptionPane. ShowMessageDialog (null, "please enter the user name", "message", JOptionPane. WARNING_MESSAGE);
//this. The clear ();

} else if (password_jtf getText (). The isEmpty ()) {

JOptionPane. ShowMessageDialog (null, "please enter the password", "message", JOptionPane. WARNING_MESSAGE);
//this. The clear ();

}

} else if (um participant etActionCommand ()=="reset") {
The clear ();
}

}

//user logs in judgment method, check the account password, attention should be paid to the database definition field length and the length of the input text box may
//not the same, so want to add the trim () to remove all Spaces format, then compare,

Public void uselogin () {

//connect to the database
Mysql. ConnectSQL ();
Mysql. SQLverify (userName_jtf. GetText (), password_jtf. The getText ());
System. The out. Println (mysql. Mypwd);
If (mysql. Myuserword. Trim (.) the equals (userName_jtf. The getText (). The trim ())
& & Mysql. Mypwd. Trim (.) the equals (password_jtf. The getText (). The trim ()))//trim () removes white Spaces at the left and the right of the character sequence, does not contain any output format string
{
System. The out. Println (" login success ");
JOptionPane. ShowMessageDialog (null, "login successfully!" , "message", JOptionPane WARNING_MESSAGE);
The clear ();
//close the current interface
The dispose ();
//create a new interface
Home Home=new Home ();

} else if (userName_jtf getText (). The isEmpty () & amp; & nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related