I am working with javafx and mysql-connector-java-5.1.45-bin library. The problem is i cannot insert new data into my column. There are not red underlines which are declaring errors. It is executed but is not inserting any data to my column with the name of patients. But in patients there are 8 columns. By the way in tutorial is told that it will insert the single data to the all columns. What is a problem?
Here is my code (FXMLDocumentController.java):
package avicenna;
import connectivity.ConnectionClass;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
public class FXMLDocumentController implements Initializable {
@FXML
private Button signinbtn;
@FXML
private Button backto;
@FXML
private Button patients;
@FXML
private Button insert;
@FXML
private Label lpass;
@FXML
private Label lname;
@FXML
private Label lage;
@FXML
private Label lgender;
@FXML
private Label lregion;
@FXML
private Label ltest;
@FXML
private Label lresult;
@FXML
private Label lblood;
@FXML
private TextField ipass;
@FXML
private TextField iname;
@FXML
private TextField iage;
@FXML
private TextField igender;
@FXML
private TextField iregion;
@FXML
private TextField itest;
@FXML
private TextField iresult;
@FXML
private TextField iblood;
@FXML
void go1btn(ActionEvent event) throws Exception {
try{
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("signin.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.setTitle("Sign In");
stage.setScene(new Scene(root1));
stage.show();
Stage stageclose = (Stage) signinbtn.getScene().getWindow();
stageclose.close();
}
catch(Exception e) {
e.printStackTrace();
}
}
@FXML
void backtomain(ActionEvent event) throws Exception {
try{
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("FXMLDocument.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.setTitle("Main window");
stage.setScene(new Scene(root1));
stage.show();
Stage stageclose = (Stage) backto.getScene().getWindow();
stageclose.close();
}
catch(Exception e) {
e.printStackTrace();
}
}
@FXML
void patients(ActionEvent event) throws Exception {
try{
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("FXML.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.setTitle("Patients");
stage.setScene(new Scene(root1));
stage.show();
Stage stageclose = (Stage) patients.getScene().getWindow();
stageclose.close();
}
catch(Exception e) {
e.printStackTrace();
}
}
@FXML
void insert(ActionEvent event) throws SQLException {
ConnectionClass connectionClass = new ConnectionClass();
Connection connection = connectionClass.getConnection();
String sql = "INSERT INTO PATIENTS VALUES('"+iname.getText()+"')";
Statement statement = connection.createStatement();
statement.executeUpdate(sql);
//lname.setText(iname.getText());
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
Here is my connectivity package from the same project(ConnectionClass.java):
package connectivity;
import java.sql.Connection;
import java.sql.DriverManager;
public class ConnectionClass {
public Connection connection;
public Connection getConnection(){
String dbName = "avicenna2";
String userName = "root";
String password = "";
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost/"+dbName,userName,password);
}
catch (Exception e){
e.printStackTrace();
}
return connection;
}
}