我想獲取客戶端到達日期並將其與我的SQL數據庫進行比較,以查看在我的數據庫中是否存在相同的日期。然而,我收到以下錯誤:The operator > is undefined for the argument type(s) java.lang.String, java.lang.String
Java和SQL比較日期
PS我需要不使用SQL查詢
public void makeNewReservation() throws ParseException {
// Enter informations
System.out.println("Date of arrivel?");
Scanner in = new Scanner(System.in);
String date_entree = in.next();
System.out.println("Date of exit? dd/MM/yyyy");
String date_sortiee = in.next();
calculateDaysDifference(date_sortiee, date_entree);
public void calculateDaysDifference(String date_entree, String date_sortiee) throws ParseException{
ConnectionMySQL myConnection=new ConnectionMySQL();
Connection conSQL=myConnection.startDBConnection();
boolean connectionOK=myConnection.checkConnection(conSQL);
String query = ("SELECT `START_DATE`,`END_DATE` FROM `room_booking");
//if everything is fine with the connection, i try to execute a query
if (connectionOK){
try{
ResultSet mesResultats=myConnection.executeQuery(conSQL, query);
//the while loop is just for me to check the dates
while (mesResultats.next()) {
System.out.println("START_DATE: "+mesResultats.getString(1)+" END_DATE : "+ mesResultats.getString(2));
if (date_entree > mesResultats.getString(1){
System.out.println("cant reserve room room reserved already");
}
}
// je ferme la connexion
conSQL.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
爲什麼你不能在db中比較嗎? –
這很簡單。你有絃樂。你正在試圖將它們比作數字。在這裏:'if(date_entree> mesResultats.getString(1){'或者轉換它們,如果這就是你想要的,或者使用'String.Compare()' – MikeTheLiar
老師想要Java代碼!:) –