I'm trying to add data from a datepicker into my db, but after submitting the query, in the db, no date in the Date column has been added, I'm pretty sure the way that I'm getting the date from the datepicker in my code is awfully wrong, but I can't seem to find a workaround..
package LicentaApp;
import javafx.scene.control.DatePicker;
import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ResourceBundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.sqlite.SQLiteErrorCode;
import org.sqlite.SQLiteException;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import java.sql.Date;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class AddProgramareController implements Initializable {
ObservableList Timestamp=FXCollections.observableArrayList();
@FXML
private TextField Nume;
@FXML
private TextField Prenume;
@FXML
private TextField Ora;
@FXML
private DatePicker Data; Data is date in my language btw
@FXML
private TextField Departament;
@FXML
private TextField Doctor;
@FXML
private TextField Nr_telefon;
public void initialize(URL location, ResourceBundle resources) {
}
@FXML
private void AddProgramare(ActionEvent event) throws SQLException, IOException {
String Interogare1= "INSERT INTO programaritest(Nume,Prenume,Data,Ora,Departament,Doctor,Nr_telefon) VALUES(?,?,?,?,?,?,?)";
String nume=Nume.getText();
String prenume=Prenume.getText();
String data=Data.getPromptText(); *Date
String ora=Ora.getText();
String departament=Departament.getText();
String doctor=Doctor.getText();
String nr_telefon=Nr_telefon.getText();
try {
ConectaredB ConectaredB=new ConectaredB();
Connection conexiune=ConectaredB.logareDB();
PreparedStatement MG = conexiune.prepareStatement(Interogare1);
MG.setString(1, nume);
MG.setString(2, prenume);
MG.setString(3, data); *Date
MG.setString(4, ora);
MG.setString(5, departament);
MG.setString(6, doctor);
MG.setString(7, nr_telefon);
MG.executeUpdate();
((Node)event.getSource()).getScene().getWindow().hide();
Stage PS= new Stage();
FXMLLoader incarcator= new FXMLLoader();
Pane parinte = incarcator.load(getClass().getResource("/LicentaApp/Departamente.fxml").openStream());
Scene scena = new Scene(parinte);
scena.getStylesheets().add(getClass().getResource("Style1212.css").toExternalForm());
PS.setScene(scena);
PS.show();
System.out.println("Programare adaugata muchacho");
} catch (SQLException exceptie1) {
exceptie1.printStackTrace(); //
}
}
}
No error message, no nothing, it just doesn't work.