Prepared Statements and unbound variables

P

Peter Davies

Hi all; here's hoping you've got better eyes than me.

Code:
String sql = "select duration, dialed_number, st from " +
"(select duration, dialed_number, to_char(start_time, " +
"'YYYY-MM-DD HH24:MI:SS AM') st, row_number() over " +
"(order by start_time desc) r from billing_record where " +
"subscriber_id = ?) where r between 1 and ?";

PreparedStatement vStatement = vConn.prepareStatement(sql);
vStatement.setInt(1, subscriberid);
vStatement.setInt(2, numCalls);
ResultSet rs = vStatement.executeQuery(sql);


Error:
java.sql.SQLException: ORA-01008: not all variables bound

I'm damn sure that I've only got two variables in the SQL statement, and
that I'm setting both of them. What's going on here?
 
J

Jacques-Olivier Haenni

Hi,

Why do you want to pass the SQL string as argument to
vStatement.executeQuery?

Just do 'ResultSet rs = vStatement.executeQuery()' and it'll work fine.

Jacques-Olivier
 
P

Peter Davies

Hi,

Why do you want to pass the SQL string as argument to
vStatement.executeQuery?

Just do 'ResultSet rs = vStatement.executeQuery()' and it'll work fine.

Jacques-Olivier

AHA!

Glad it was a simple problem. Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top