我正在尝试编码导航按钮,就像我正在尝试编码按钮,按钮前一个,按钮优先,按钮最后一个在我的cotroller中,但似乎我的日期问题在哪里索引是我所有的日期与索引给我红线。其余的不会给我任何问题,除了索引区域中的日期,我有
public void next(int index)throws SQLExeception{
package hotel.management.system;
import java.net.URL;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TextField;
import javax.swing.JOptionPane;
/**
* FXML Controller class
*
* @author PHILSERVER
*/
public class CustomersnavigationController implements Initializable {
private ArrayList<String> fullname = new ArrayList<>();
private ArrayList<String> nationality = new ArrayList<>();
private ArrayList<String> countryofresidence = new ArrayList<>();
private ArrayList <String> dateofbirth = new ArrayList<>();
private ArrayList<String> profession = new ArrayList<>();
private ArrayList<String> passport = new ArrayList<>();
private ArrayList<String> roomtype = new ArrayList<>();
private ArrayList<String> roomnumber = new ArrayList<>();
private ArrayList<String> dateofarrival = new ArrayList<>();
private ArrayList<String> goingtowhere = new ArrayList<>();
private ArrayList<String> numberofgroup = new ArrayList<>();
private ArrayList<String> dateofdepature = new ArrayList<>();
private ArrayList<String> periodstayed = new ArrayList<>();
private ArrayList<String> numberofnight = new ArrayList<>();
private ArrayList<String> roomrate = new ArrayList<>();
private ArrayList<String> total = new ArrayList<>();
private int index = 0;
private LocalDate date;
private String selectedDate;
@FXML
private TextField tfNumberofgroup;
@FXML
private TextField tfProfession;
@FXML
private TextField tfRoomnumber;
@FXML
private TextField tfRoomtype;
@FXML
private TextField tfTotal;
@FXML
private TextField tfPassport;
@FXML
private TextField tfFullname;
@FXML
private TextField tfNumberofnight;
@FXML
private Button Last;
@FXML
private TextField tfNationality;
@FXML
private TextField tfRoomrate;
@FXML
private DatePicker dpDate;
@FXML
private Button Next;
@FXML
private DatePicker dpDepaturedate;
@FXML
private TextField tfGoingtowhere;
@FXML
private Button Previous;
@FXML
private TextField tfSearch;
@FXML
private Button First;
@FXML
private DatePicker dpArrivaldate;
@FXML
private TextField tfCountryofresidence;
@FXML
private Connection con;
@FXML
private java.sql.Statement stmt;
@FXML
private ResultSet rs;
@FXML
void search(ActionEvent event) {
if (tfSearch.getText().equals("")){
JOptionPane.showMessageDialog(null," Enter fullname please !!!");
}else{
if(checkName()){
search();
}else{
JOptionPane.showMessageDialog(null,"fullname does not exist");
}
}
}
@FXML
void first(ActionEvent event) throws SQLException {
index=0;
move();
next(index);
}
@FXML
void next(ActionEvent event) throws SQLException {
index=index+1;
move();
next(index);
}
@FXML
void previous(ActionEvent event) throws SQLException {
if (index <0) {
index = 0;
} else {
index=index-1;
move();
next(index);
}
}
@FXML
void last(ActionEvent event) throws SQLException {
move();
index=fullname.size()-1;
next(index);
}
private void move() {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch(ClassNotFoundException e) {
JOptionPane.showMessageDialog(null,"Unable to register class "+e.getMessage());
}
try {
con = DriverManager.getConnection("jdbc:mysql://localhost/level2","root","addison");
stmt = con.createStatement();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null,"Unable to connect to database "+e.getMessage());
}
try {
String sql;
sql = "select * from customerinformaton";
rs = stmt.executeQuery(sql);
while (rs.next()) {
fullname.add(rs.getString("fullname"));
nationality.add(rs.getString("nationality"));
countryofresidence.add(rs.getString("countryofresidence"));
dateofbirth.add(rs.getString("dateofbirth"));
profession.add(rs.getString("profession"));
passport.add(rs.getString("passport"));
roomtype.add(rs.getString("roomtype"));
roomnumber.add(rs.getString("roomnumber"));
dateofarrival.add(rs.getString("dateofarrival"));
goingtowhere.add(rs.getString("goingtowhere"));
numberofgroup.add(rs.getString("numberofgroup"));
dateofdepature.add(rs.getString("dateofdepature"));
numberofnight.add(rs.getString("numberofnight"));
roomrate.add(rs.getString("roomrate"));
total.add(rs.getString("total"));
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(null,"Unable to retrieve record "+e.getMessage());
}
}
private void next(int index) throws SQLException {
tfFullname.setText(fullname.get(index));
tfNationality.setText(nationality.get(index));
tfCountryofresidence.setText(countryofresidence.get(index));
java.sql.Date d7 = rs.getDate(index);
dpDate.setValue(d7.toLocalDate());
tfProfession.setText(profession.get(index));
tfPassport.setText(passport.get(index));
tfRoomtype.setText(roomtype.get(index));
tfRoomnumber.setText(roomnumber.get(index));
java.sql.Date d4 = rs.getDate(index);
dpArrivaldate.setValue(d4.toLocalDate());
tfGoingtowhere.setText(goingtowhere.get(index));
tfNumberofgroup.setText(numberofgroup.get(index));
java.sql.Date d6 = rs.getDate(index);
dpDepaturedate.setValue(d6.toLocalDate());
tfNumberofnight.setText(numberofnight.get(index));
tfRoomrate.setText(roomrate.get(index));
tfTotal.setText(total.get(index));
}
private boolean checkName(){
try {
Class.forName("com.mysql.jdbc.Driver");
} catch(ClassNotFoundException e) {
JOptionPane.showMessageDialog(null,"Unable to register class "+e.getMessage());
}
try {
con = DriverManager.getConnection("jdbc:mysql://localhost/level2","root","addison");
stmt = con.createStatement();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null,"Unable to connect to database "+e.getMessage());
}
try{
String sql;
sql="select * from customerinformation where fullname='"+tfSearch.getText()+"'";
rs=stmt.executeQuery(sql);
if(rs.next()){
return true;
}
}catch (SQLException e){
JOptionPane.showMessageDialog(null,"unable to retrieve record"+ e.getMessage());
}
return false;
}
private void search(){
try {
Class.forName("com.mysql.jdbc.Driver");
} catch(ClassNotFoundException e) {
JOptionPane.showMessageDialog(null,"Unable to register class "+e.getMessage());
}
try {
con = DriverManager.getConnection("jdbc:mysql://localhost/level2","root","addison");
stmt = con.createStatement();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null,"Unable to connect to database "+e.getMessage());
}
try {
String sql;
sql = "select * from customerinformation where fullname='"+tfSearch.getText()+"'";
rs = stmt.executeQuery(sql);
while(rs.next()){
tfFullname.setText(rs.getString("fullname"));
tfNationality.setText(rs.getString("nationality"));
tfCountryofresidence.setText(rs.getString("countryofresidence"));
java.sql.Date dm = rs.getDate("Dateofbirth");
dpDate.setValue(dm.toLocalDate());
tfProfession.setText(rs.getString("profession"));
tfPassport.setText(rs.getString("passport"));
tfRoomtype.setText(rs.getString("roomtype"));
tfRoomnumber.setText(rs.getString("roomnumber"));
java.sql.Date da = rs.getDate("dateofarrival");
dpArrivaldate.setValue(da.toLocalDate());
tfGoingtowhere.setText(rs.getString("goingtowhere"));
tfNumberofgroup.setText(rs.getString("numberofgroup"));
java.sql.Date dd = rs.getDate("Dateofdepature");
dpDepaturedate.setValue(dd.toLocalDate());
tfNumberofnight.setText(rs.getString("numberofnight"));
tfRoomrate.setText(rs.getString("roomrate"));
tfTotal.setText(rs.getString("total"));
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(null,"Unable to retrieve record "+e.getMessage());
}
}
public static final LocalDate LD (String date)
{
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
CharSequence dateString = null;
LocalDate localDate = LocalDate.parse(dateString, formatter);
return localDate;
}
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}