I'm getting the error:
the multi-part identifier "IC.industry" could not be bound
when making this SQL query from a JSP page via JDBC:
select C.company, C.shname, C.fullname, count(d_to_c.designer)
from companies C
left join ind_to_c IC on C.company = IC.company
left join d_to_c on C.company= d_to_c.company
where IC.industry = ?
group by C.company, C.shname, C.fullname
order by C.shname
and I'm trying to run it as a prepared statement, where I'm setting the parameter via (for example) stmt.setObject(1, 7)
prior to running stmt.executeQuery()
.
Now, what's weird is: If I execute this with the ?
and set the parameter as I just mentioned, I get the "could not be bound" error. If, however, I just change the query and hardcode the number 7 into the text of the query, it works!
So it has something to do with binding that parameter.
But I can't seem to figure out what.
Anybody?
UPDATE: Per request, the table definition for ind_to_c
:
industry - int(11)
company - int(11)
(it's just a table that defines the m2m relationship between industries and companies)
UPDATE 2: Also per request, the full JSP code. I had to pull this out of a call to an abstraction of the database connection (which we use to store prepared statements, etc.
// conn has been initialized as the db connection object.
int parent_id = 7;
PreparedStatement ps = conn.prepareStatement("select C.company, C.shname, C.fullname, count(d_to_c.designer) from companies C left join ind_to_c IC on C.company = IC.company left join d_to_c on C.company = d_to_c.company where IC.industry = ? group by C.company, C.shname, C.fullname order by C.shname");
ps.setObject(1, parent_id);
ResultSet rs = null;
rs = ps.executeQuery();