BabyFace
asked on
PreparedStatements ? after WHERE
Hi,
Can I put the ? marker after the WHERE clause?
Like:
SQL = "SELECT * FROM mytable WHERE ?";
PreparedStatement pstmt = conn.prepareStatement(SQL) ;
pstmt.setString(1,"ID = 23 AND ODJ = 23 AND ...(etc..)");
ResultSet rs = pstmt.executeQuery();
Thanks
Can I put the ? marker after the WHERE clause?
Like:
SQL = "SELECT * FROM mytable WHERE ?";
PreparedStatement pstmt = conn.prepareStatement(SQL)
pstmt.setString(1,"ID = 23 AND ODJ = 23 AND ...(etc..)");
ResultSet rs = pstmt.executeQuery();
Thanks
ASKER
Hi,
The problem is that I have a variable constaint list.
Sometimes after the WHERE clause has 1 constaint other times it may have 5 or 7 or 13 or etc...
I was wondering if preparedstatments could handle this structure?
Thanks
The problem is that I have a variable constaint list.
Sometimes after the WHERE clause has 1 constaint other times it may have 5 or 7 or 13 or etc...
I was wondering if preparedstatments could handle this structure?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can still use a PreparedStatement, you just have to build up your SQL yourself before create your PreparedStatement.
SQL = "SELECT * FROM mytable WHERE id = ? and odj = ?";
pstmt.setInt(1,23);
pstmt.setInt(2,23);