What does "=?" Mean represent when used in a SQL query

I am new to SQL, and I'm currently processing a Java programmer. When I print one of my query select statements, the script contains sql syntax:

SELECT * from database WHERE id = ? 

I just want to know what to do =? ? I have searched for searches and I cannot find the answer.

+4
source share
5 answers

This is not a SQL notation, but JDBC (Java Database Connectivity) . ? replaced by the parameter specified separately. Using this approach, instead of trying to substitute the parameter yourself into a string, helps prevent the risk of SQL injection .

+5
source

? is a place holder, parameter, so you can pass it dynamically and return different results for different parameters.

Somewhere in the code, you should see that it adds this parameter to the Statement object and executes it.

+1
source

Most likely you are using a tool that replaces "?" with actual value. I saw this in other tools like SQL DTS (Data Transformation Services) ... but it shows how old I am :)

? is not part of the SQL language.

+1
source

? is the place owner used in SQL queries when used with JDBC Prepared Report . Using a prepared statement, advantages over a normal statement , especially when you reuse it (say, in a loop).

+1
source

Here is an example:

 PreparedStatement ps = connection.prepareStatement("select name from users where user_name = ?"); ps.setString(1, "user1"); 

"?" is replaced with "user1" when the request is run and the username with the username "user1" is returned.

0
source

Source: https://habr.com/ru/post/1394536/


All Articles