Why there are double question marks in JDBC code

I am in the process of converting SQL JDBC statements to ODBC / DB2 with PHP. I came across the following sentence, which bothers me.

WHERE phid = ??id 

My first instinct was that it was for prepared statements, but now I'm not sure. Is this a JSP / JDBC thing? Google / stack added nothing.

+7
source share
2 answers

Wow! Mabye is just a normal binder variable, but with 2 lines! The java.sql.Conneciton documentation (quick read) says nothing that they should be separated by spaces. Please write more code so we can see if there are any setString calls to add binding variables (s).

For example, something like this:

 pstmt = conn.prepareStatement("select blah from blah WHERE phid = ??id and blah blah"); pstmt.setString(1, "customer_"); pstmt.setString(2, "order_"); 

I have never seen anything like it, but maybe this is what they did?

EDIT: I tried! And that gave me a mistake! I wonder if you found some dead code? This is what I tried:

  sql.append("SELECT A.ID, A.GROUP_NUMBER, A.GROUP_NAME "); sql.append("FROM " + tab1 + " A "); sql.append("INNER JOIN " + tab2 + " B "); sql.append("ON (A.ID = B.GROUP_ID) "); sql.append("WHERE B.THREAD_ID = ? "); sql.append("AND B.THREAD_ID = ??ID "); sql.append("ORDER BY A.ID "); // ... conn = getConn(); pstmt = conn.prepareStatement(sql.toString()); pstmt.setInt(1, threadId); pstmt.setString(2, "B."); pstmt.setString(3, "THREAD_"); 

I got this error:

ILLEGAL SYMBOL "?". SOME SYMBOLS THAT MIGHT BE LEGAL ARE: MICROSECONDS MICROSECOND SECONDS SECOND MINUTES MINUTE HOURS. SQLCODE=-104, SQLSTATE=42601, DRIVER=3.57.82

+1
source

As others commented (sorry, not enough comments for comments), this is probably somehow a way of handling named parameters. I cannot find any references to it either in JDBC or in any ORM structures that I know, so it could be a custom JDBC / ORM environment created for this particular application. Seeing more sample code will certainly help.

0
source

All Articles