-3

So I have a table in my database with reservations. In Java I only want to show the reservations of today and beyond.

PreparedStatement statement = con.prepareStatement(
                "SELECT reservatieID,klanten.voornaam,klanten.achternaam,kamerID,startDatum,eindDatum "
                + "FROM reservatie "
                + "INNER JOIN klanten ON reservatie.klantID = klanten.klantID"
                + "WHERE eindDatum =>?");
String now = basisLogin.getDate();
statement.setString(1, now);
ResultSet resultSet = statement.executeQuery(); 

So this is my code. The string of today's date is in this format: yyyy-MM-dd

This is the error I get:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have anerror in your SQL syntax; check the manual that corresponds to your MySQL   server version for the right syntax to use near 'eindDatum >'2017-03-07'' at line 1
java.lang.ArrayIndexOutOfBoundsException: 0 >= 0    

What am I doing wrong?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

2 Answers2

-3

Use one of the functions described here, depending on if you want to include time.

For example:

...WHERE eindDatum => Current_date()");
Community
  • 1
  • 1
Andrew S
  • 2,509
  • 1
  • 12
  • 14
  • The code is fine as is and complies so there is no syntax error. It's a runtime error from attempting to use a string with a date column. – Andrew S Mar 07 '17 at 17:21
  • The Java code may compile, but it's a syntax error in the SQL. So says the runtime exception (`MySQLSyntaxErrorException`). That SQL is not *fine*. – Andreas Mar 07 '17 at 17:23
  • The cause was ultimately from mixing string with date, reported as that type of exception. Plus, String now = basisLogin.getDate() and statement.setString(1, now); are unnecessary. – Andrew S Mar 07 '17 at 17:29
  • So you're claiming that the **syntax error** is caused by the comparison of valid column name `eindDatum` with the valid string literal `'2017-03-07'`, and not by the incorrect use of `=>` (which should be `>=`) or the missing space in `ON reservatie.klantID = klanten.klantIDWHERE eindDatum =>'2017-03-07'`? Sorry, but you're wrong. It's definitely the missing space before `WHERE` that is the main problem, as I've already [said in a comment](http://stackoverflow.com/questions/42654158/check-if-date-in-database-is-bigger-then-today-java-sql/42654334?noredirect=1#comment72434487_42654158). – Andreas Mar 07 '17 at 17:35
-3

Use: WHERE eindDatum => CURDATE()

Ossin Java guy
  • 365
  • 3
  • 12