Calling a stored procedure with many arguments
From: Tommy Karlsson (tommy.karlsson.350_at_student.lu.se)
Date: 03/26/04
- Next message: Robert Klemme: "Re: in memory db of 200 GB"
- Previous message: Manpreet: "JSP ORACLE CONNECTIVITY"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 26 Mar 2004 13:34:49 +0100
Hi!
First Iīd like to apologize for double-posting this question. I first posted
it in comp.lang.java.help, but then realized this is probably a better place
to post it.
Now for my problem;
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
Someone in comp.lang.java.help told me that the arguments should be
comma-separated, but that just gives me this error:
[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Line 1: Incorrect
syntax near ','.
So, from what I understand, thatīs not the issue.
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
statement (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
- Next message: Robert Klemme: "Re: in memory db of 200 GB"
- Previous message: Manpreet: "JSP ORACLE CONNECTIVITY"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|