Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2004

Tip: Looking for answers? Try searching our database.

CallableStatement with many arguments

Thread view: 
Tommy Karlsson - 25 Mar 2004 10:14 GMT
Hi!

First some system info: I?m using MS SQL-Server 2000 and Microsoft SQLServer
2000 Driver for JDBC (which is java 1.3 compatible, and uses JDBC spec 2.0).

What I?m trying to do is to call a stored procedure in the database with
quite alot of arguments (41 in this example).

The call is set up dynamically, using a few steps;

1. put the name of the procedure in a string
String procedure="SaveOpRegWeb"; //just as an example, this is done
dynamicaly of course, but that isnt very interesting here.

2. create a string with a number of space-separated questionmarks, that
represents the arguments
//attributes is a LinkedList with a number of names of arguments in it (a
bit confusing name). The actual literals, with names corresponding to the
names of the arguments, are all stored in a LiteralTable as explained later.
String arguments="";
for(int i=0;i<attributes.size();i++) {
  arguments+="? ";
}
arguments.trim(); // just to remove the ending white-space

3. create a CallableStatement object
//sqlconn is an Object of my own class SQLServerConnection, where
getConnection() returns a java.sql.Connection object.
CallableStatement statement=sqlconn.getConnection().prepareCall("{call
"+procedure+" "+arguments+"}");

4. map the questionmarks in the arguments-string to the actual arguments
//this goes something like this (whith some more checks here and there,
which arent very interesting)
//literals is an object of my own type LiteralTable, that hold a number of
Literals
//a Literal is also my own type and hold a literal?s value, type (of my own
defined set of types) and SQLType, which is the type as defined by
java.sql.Types

   ListIterator li = attributes.listIterator();
   Literal l;

   for (int index = 1; li.hasNext(); index++) {
     String next = (String)li.next();
     l = literals.getLiteral(next);
     ps.setObject(index, l.getValue(), l.getSQLType());
  }

5. execute the CallableStatement
//ok, everything works just fine this far, but when i try to execute the sta
tement (doing statement.execute();)i get this error:
[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]The identifier that
starts with '
SaveOpRegWeb@P1@P2@P3@P4@P5@P6@P7@P8@P9@P10@P11@P12@P13@P14@P15@P16@P17@P18@
P19@P20@P21@P22@P23@P24@P25@P26@P27@P28@P29@P30@P31@' is too long. Maximum
length is 128.

As indicated by that string, the maximum number of parameters allowed seems
to be 31 in this case.
So my question is obviously: How do I call a stored procedure with more
arguments than that?
I should also mention that changing the number of arguments of the stored
procedure in the database is _not_ an option.

To solve this issue is quite crucial to my current project, so I would
really appreciate some help on this one!
Thanks in advance
/Tommy Karlsson
Virgil Green - 25 Mar 2004 20:27 GMT
> Hi!
>
[quoted text clipped - 13 lines]
> represents the arguments
> file://attributes is a LinkedList with a number of names of arguments in
it (a
> bit confusing name). The actual literals, with names corresponding to the
> names of the arguments, are all stored in a LiteralTable as explained later.
[quoted text clipped - 12 lines]
> 4. map the questionmarks in the arguments-string to the actual arguments
> file://this goes something like this (whith some more checks here and
there,
> which arent very interesting)
> file://literals is an object of my own type LiteralTable, that hold a
number of
> Literals
> file://a Literal is also my own type and hold a literal?s value, type (of
my own
> defined set of types) and SQLType, which is the type as defined by
> java.sql.Types
[quoted text clipped - 10 lines]
> 5. execute the CallableStatement
> file://ok, everything works just fine this far, but when i try to execute
the sta
> tement (doing statement.execute();)i get this error:
> [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]The identifier that
> starts with '

SaveOpRegWeb@P1@P2@P3@P4@P5@P6@P7@P8@P9@P10@P11@P12@P13@P14@P15@P16@P17@P18@
> P19@P20@P21@P22@P23@P24@P25@P26@P27@P28@P29@P30@P31@' is too long. Maximum

You didn't provide a space after your procedure and you must also separate
your arguments with commas, not just spaces.

- Virgil
Tommy Karlsson - 26 Mar 2004 13:43 GMT
> You didn't provide a space after your procedure and you must also separate
> your arguments with commas, not just spaces.
>
>  - Virgil

Actually I did provide a space after the name of the procedure when i called
prepareCall("{call "+procedure+" "+arguments+"}");

And when it comes to commas, it just gives me this message when I try it:
[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Line 1: Incorrect
syntax near ','.

I dont know if it?s me doing something wrong, or what. From what I can read
out of the API, I agree on you that there should be commas.

And, I posted the very same question in comp.lang.java.databases, because I
realized thats where it belongs.
Sorry for posting in wrong group (I?m new to this).

/ralle
Virgil Green - 29 Mar 2004 20:58 GMT
> > You didn't provide a space after your procedure and you must also separate
> > your arguments with commas, not just spaces.
[quoted text clipped - 3 lines]
> Actually I did provide a space after the name of the procedure when i called
> prepareCall("{call "+procedure+" "+arguments+"}");

Yes, you did. I missed it. The error message you presented (where did all
those @s come from?) threw me. That and some line wrap.

> And when it comes to commas, it just gives me this message when I try it:
> [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Line 1: Incorrect
> syntax near ','.
>
> I dont know if it?s me doing something wrong, or what. From what I can read
> out of the API, I agree on you that there should be commas.

Yes, there should be commas. have you constructed the entire string and
printed/output it to verify that it is really what you think it is? Are you,
perhaps, including a comma after the last parameter?

Also, there should *not* be a closing brace.

- Virgil
Virgil Green - 29 Mar 2004 21:17 GMT
> > > You didn't provide a space after your procedure and you must also
> separate
[quoted text clipped - 22 lines]
>
> Also, there should *not* be a closing brace.

I just reviewed some of my code. The closing brace is not present in most of
preparedStatement creation code, but I do have one routine that does have a
closing brace and it isn't complaining.

- Virgil


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.