0

I have difficulties with a statement in the Java code, that is needed to be read in the SQL. The statement contains ? and is not understandable for me what is it's meaning. The code goes like this:

    String sql = "SELECT lsw_id, lsw_planed_time, lsw_start_time, lsw_finish_time, lsw_exe_result, lsw_message FROM "
            + ENTITY_NAME
            + " WHERE lsw_planed_time < ? AND lsw_start_time IS NULL";

I would please require some help.

khelwood
  • 55,782
  • 14
  • 81
  • 108
Martin
  • 1
  • query parameter – Jacek Cz Aug 17 '18 at 09:20
  • The question mark indicates that a parameter will be given when the query is executed, and the parameter will be used in the place of the `?` in the query. – khelwood Aug 17 '18 at 09:20
  • These are place holder which will be later on be passed as parameters – Nicholas K Aug 17 '18 at 09:20
  • It is use for the parammter, see the next lines of code. ;) – Vinh Can Code Aug 17 '18 at 09:20
  • 2
    It's used for a [PreparedStatement](https://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html) –  Aug 17 '18 at 09:22
  • An SQL statement template is created and sent to the database. Certain values are left unspecified, called parameters (labeled "?") Example: INSERT INTO MyGuests VALUES(?, ?, ?). The database parses, compiles, and performs query optimization on the SQL statement template, and stores the result without executing it. At a later time, the application binds the values to the parameters, and the database executes the statement. The application may execute the statement as many times as it wants with different values. – Deepak N Aug 17 '18 at 09:30

1 Answers1

0

If you want to use your query many times with different 'lsw_planed_time' you just place a parameter in the query. A parameter is a placeholder for a value that is supplied when the query runs.

Look at the description

Roman Haivaronski
  • 530
  • 2
  • 5
  • 18