prepared statement - JDBC PreparedStatement, UNION Select and parameter passing -


OK, I know the answer is simple and I am feeling very dumb but ...

Java JDK 1.7, Sybase JDBC Driver

Code snippet:

  string  by & lt; blah blah & gt; Where date1 =? UNION Select & lt; blah & gt; from & lt; blah blah & gt; where date2 =? ';;; Connection conn = ConnectionManager.getConnection (); Prepare the settings stmt = conn.prepareStatement (SQL) ); Logger.info ("Permanent count:" + stmt.getParameterMetaData (). GetParameterCount ()); Stmt.setDate (1 new java sql.Date (date.getTime ()); stmt.setDate (2, not Or java.sql.Date (date.getTime ()); results set rs = stmt.executeQuery (); while rsnext ()) {// the rest of code}   
  1. So why parmeter only count 1?
  2. Program throws an error complaint: java.sql.SQLException: Invalid parameter index 2.
  3. If I reduce SQL to any piece Let me decrease the setdate in 1 and then it works fine.
  4. With the union SQL runs fine in an interactive SQL session (just filled with a certain date)

    I just ran into this problem, and it was very useful, it is not the union section which is throwing errors; This is the date you are passing. If you are using to_date () (ambiguous with your code snippet), then you need to pass a string (instead of date) in the query. Good luck!

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -