executeQuery Can't pass variable to SQL. :-( Why?

From: Nelson Broat <nelson.broat_at_mail.cuny.edu>
Date: 8 Aug 2003 15:16:41 -0700
Message-ID: <32159d9d.0308081416.7eadabe_at_posting.google.com>



In jsp land you can have the following:

<%
String name = "Nelson";
%>

Hi, my name is <%= name %>.

Such that, in your browser you see:

Hi, my name is Nelson.

I am trying to do similiar with the executeQuery() method and it is not working. Can anyone tell me what is wrong with the syntax I'm using?
The jsp won't compile. It seems to not want to allow me to pass a variable called recordkey, which in this example has a value of 999. But in a loop structure which I'm looking to create, the value would change. Thanks for any and all help.

<%_at_ page import="java.util.*,

                 java.text.*, 
                 java.io.*, 
                 java.sql.*"

    contentType="text/html; charset=UTF-8"
%>

<%
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); con = DriverManager.getConnection("jdbc:oracle:thin:_at_dsn:portnumber:dbinstance","userid","passwd"); stmt = con.createStatement();
int recordkey = 999;
String sql = "SELECT * FROM db.db WHERE db.column = <%= recordkey %>"; rs = stmt.executeQuery(sql);
%>

Nelson Broat
nelson.broat_at_mail.cuny.edu Received on Sat Aug 09 2003 - 00:16:41 CEST

Original text of this message