Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are there double question marks in JDBC code

Tags:

java

sql

jdbc

I'm in the process of converting JDBC sql statements over to ODBC/DB2 with PHP. I came across the following clause that confuses me.

WHERE phid = ??id

My first instinct was that it was for prepared statements, but now I'm not so sure. Is this a JSP/JDBC thing? Google/stack haven't turned up anything.

like image 478
sprite7 Avatar asked Mar 13 '13 18:03

sprite7


1 Answers

Whoa! Mabye it is just a normal bind variable, but having 2 in a row! There is nothing in the documentation of java.sql.Conneciton (quick read) that says they have to be separated by spaces. Please post more code so we can see if there are any setString calls to add the bind variable(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've never seen anything like this, but maybe this is what they were doing?

EDIT: I tried it! And it gave me an error! 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

like image 113
Jess Avatar answered Oct 11 '22 16:10

Jess