package sample2; import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXTextField; import java.net.URL; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.util.ResourceBundle; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javax.swing.JOptionPane; public class FXMLDocumentController implements Initializable { Connection conn=null; PreparedStatement pst=null; @FXML private JFXTextField passwordtxt; @FXML private JFXTextField usernametxt; @FXML private JFXButton loginbtn; @FXML void loginbtnclick(ActionEvent event) { String user=usernametxt.getText(); String pass=passwordtxt.getText(); if(user.contentEquals("") && pass.contains("")) { JOptionPane.showMessageDialog(null,"Login failed"); } else { String sql="insert into new (nn,nnn) values(?,?)"; try { Class.forName("com.mysql.jdbc.Driver"); conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/userdatabase?zeroDateTimeBehavior=convertToNull","root","12345678"); pst = (PreparedStatement)conn.prepareStatement(sql); pst.setString(1,user); pst.setString(2,pass); pst.execute(); JOptionPane.showMessageDialog(null,"Record Inserted Successfully"); usernametxt.setText(null); passwordtxt.setText(null); } catch(Exception e) { // e.printStackTrace(null); } } } @Override public void initialize(URL url, ResourceBundle rb) { } }
pass.contains("")
contains
if(user.contentEquals("") || pass.contentEquals(""))
NullPointerException
FXMLDocumentController.java
try..catch
user
null
pass
if (user == null || user.isEmpty() || pass == null || pass.isEmpty())
Richard Deeming
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)