Re: Java Prepared Statement with multiple arguments



Hi. Yes you have to have a '?' for every variable in both clauses. If
you make a stored procedure like:

create procedure myInsertProc int @foo, VARCHAR(30) @bar ...
AS
BEGIN
IF NOT EXIST (SELECT * FROM MyTable WHERE MyColumn = @foo
AND MYOtherColumn = @bar ) INSERT INTO
MyTable (MyColumn) VALUES (@foo, @bar)
END

then your JDBC would only need one '?' for each column:

p = c.prepareStatement("{ call myInsertProc( ?, ? ) }");


If you can create an index for your table that enforces that
each row is unique, then you don't need to do the check. If
the row already exists the insert will fail.

HTH,
Joe Weinstein at BEA

.



Relevant Pages

  • metadata for Storedprocedure
    ... executing the stored procedure in JDBC? ... Irfan. ... Prev by Date: ...
    (comp.lang.java.databases)
  • Re: JDBC and SQL server Stored procedure exception
    ... |>> In the stored procedure, we will build a sql statement, and call ... If I can see the JDBC code that handles the ... | The way I see it, the error is generated by SQL Server, not the ... Please post your JDBC code, stored proc, and relevant table ...
    (microsoft.public.sqlserver.jdbcdriver)
  • Re: metadata for Storedprocedure
    ... executing the stored procedure in JDBC? ... to get information about all procedures of schema ... to get information about named procedure. ...
    (comp.lang.java.databases)
  • Re: Simple question - cant find answer
    ... How did you try it with JDBC? ... If I just use the Stored Procedure ... it gives me the resultset back and works just fine... ... Guide to SQL: Syntax ...
    (comp.databases.informix)
  • Problem batching DB2 stored procedure calls using JDBC
    ... I have a DB2 stored procedure that I call using JDBC. ... batch the call. ...
    (comp.lang.java.databases)