Q:

"ORA-01858: a non-numeric character was found where a numeric was expected" when writing a query in a java class

I have a web application where 3 inputs are taken from the user and after clicking search button results are displayed. The three inputs are; id (not unique), startdate and enddate. I want to be able to get the results in these situations: If the user enters 

only id
only start date (enrolldate in db table)
only end date (graduationdate in db table)
id and start date
when all the fields entered together

In my StudentManager.java class I have a SQL string like below; 
final String SQL_STU = " select " 
                + " t.name,"
                + " t.surname, " 
                + " t.lecture," 
                + " from studenttable t " 
                + " where t.school = 'CHC' " 

                + " and t.id = case when '" + studentInfo.getID() + "'" +" is null then t.id else '" + studentInfo.getID() + "' end "

                + " and t.enrolldate >= case when '" + studentInfo.getStartDate() + "' is null then t.enrolldate else to_date('" 
                +  studentInfo.getStartDate() + "', 'DD.MM.YYYY HH24:MI:SS') end " 

                + " and t.graduationdate >= case when '" + studentInfo.getEndDate() + "' is null then t.graduationdate else to_date('" 
                +  studentInfo.getEndDate() + "', 'DD.MM.YYYY HH24:MI:SS') end " ; 

I will execute this query and get the results into a result set.
I have a couple of problems with this code; for example when I comment out this part: 
            + " and t.enrolldate >= case when '" + studentInfo.getStartDate() + "' is null then t.enrolldate else to_date('" 
            +  studentInfo.getStartDate() + "', 'DD.MM.YYYY HH24:MI:SS') end " 

            + " and t.graduationdate >= case when '" + studentInfo.getEndDate() + "' is null then t.graduationdate else to_date('" 
            +  studentInfo.getEndDate() + "', 'DD.MM.YYYY HH24:MI:SS') end " ; 

It works without errors but when I give all the inputs null (id, date1, date2) it displays nothing. Shouldn't it display all the results since there is no specific id? (User will not be able to submit 3 empty fields but I am curious why it does not work like the way I mentioned? )
The other thing is when I execute the whole code (with to_date parts) it gives the error in the title. But it does not give any error when I execute like this:
  final String SQL_STU = " select " 
                    + " t.name,"
                    + " t.surname, " 
                    + " t.lecture," 
                    + " from studenttable t " 
                    + " where t.school = 'CHC' " 

                    + " and t.enrolldate >= case when '" + studentInfo.getStartDate() + "' is null then t.enrolldate else to_date('" 
                    +  studentInfo.getStartDate() + "', 'DD.MM.YYYY HH24:MI:SS') end " ;

So in summary I couldn't write the query the way I wanted. I am not that experienced with queries. If you know any better way you can also suggest it since I have come to a dead end. I also tried something with NVL but I could not make it work also.
Notes:

ID, StartDate,EndDate  are type string  in my StudentInfo.java class
id is type varchar and dates are type date in database table.(PL/SQL)

A:

The best answer to your question is to use a prepared statement:
String sql = "SELECT t.name, t.surname, t.lecture ";
sql += "FROM studenttable t ";
sql += "WHERE t.school = 'CHC' AND " 
sql += "t.id = COALESCE(?, t.id) AND ";
sql += "t.entrolldate >= COALESCE(?, t.enrolldate) AND ";
sql += "t.graduationdate >= COALESCE(?, t.graduationdate)";

PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, studentInfo.getID());
ps.setDate(2, studentInfo.getStartDate());
ps.setDate(3, studentInfo.getEndDate());
ResultSet rs = ps.executeQuery();

while (rs.next()) {
    // process a row
}

The reason why using a statement is preferred is that it frees you from having to manually marshal your Java date (and other type) variables into your Oracle SQL statement.  Instead, the above code lets the JDBC driver worry about how to convert a Java date variable to the correct format in the actual SQL code.  Also, statements allow you to write a SQL query with minimal concatenations, which reduces the chances for error and typos.
Note that you might have to call a setter other than PreparedStatement#setDate depending on the what getStartDate() and getEndDate() methods actually return in your Java code.

