#nullpointerexception
#исключение nullpointerexception
Вопрос:
Я подключаю свою программу к базе данных и делаю все, но она показывает мне ошибку, которую я не знаю, как ее решить !!
У меня есть 3 класса JDBC, регистрация, вход в систему Я загружаю connector/j 8.0.27, я подключаю его, но все равно получаю ошибку, когда запускаю его и ввожу регистрацию, затем я пишу всю информацию и нажимаю кнопку зарегистрировать, затем появляется ошибка
package jdbc_test; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class Registration extends JFrame implements ActionListener { static JLabel lb = new JLabel("Regestration Form"); static JTextField fstname = new JTextField(20); static JTextField lstname = new JTextField(20); static JTextField username = new JTextField(20); static JPasswordField password = new JPasswordField(20); static JButton regBtn = new JButton("Register"); static JButton cnlBtn = new JButton("Cancel"); Connection con = null; public Registration() { this.setTitle("Regestration"); this.setVisible(true); this.setSize(300, 200); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setLayout(new FlowLayout()); this.add(lb); fstname.setText("Enter your First Name"); lstname.setText("Enter your Last Name"); username.setText("Enter your Usernae"); password.setText("Enter your Password"); this.add(fstname); this.add(lstname); this.add(username); this.add(password); this.add(regBtn); this.add(cnlBtn); regBtn.addActionListener(this); cnlBtn.addActionListener(this); try { String db_url = "jdbc:mysql://localhost:3306/mydb?useSSL=true"; String db_username = "root"; String db_password = "FA.hb@054"; Connection con = DriverManager.getConnection(db_url, db_username, db_password); } catch (SQLException sqlException) { System.out.println(sqlException.getMessage()); } } public void actionPerformed(ActionEvent e) { if (e.getSource() == regBtn) { String fName = fstname.getText(); String lName = lstname.getText(); String uName = username.getText(); String pass = password.getText(); String sql = String.format("INSERT INTO users(fname," "lname,username,pass)n" "Values('%s','%s','%s','%s');", fName, lName, uName, pass); try { Statement s = con.createStatement(); s.executeUpdate(sql); } catch (SQLException sqlException) { System.out.println(sqlException.getMessage()); } } if (e.getSource() == cnlBtn) { } } }