Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need Urgent help

 
gaurav kant
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
m calling a stored procedure from sqlserver that is returning a NVARCHAR(max) type value.

code is like this

String procedureString="{call getname('12',?)}";
CallableStatement proc = conn.prepareCall(procedureString);
proc.registerOutParameter(1, Types.NVARCHAR);
proc.execute();
String str=prov.getNString(1);

now. database is returning a string and length of this string is more than 8000 but nvarchar size is 4000 atmost so it is truncating characters comming after 4000 place.
can nybdy help regarding this
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34681
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gaurav,
Welcome to JavaRanch!

In the future, please use a meaningful subject line. Everyone wants help - that doesn't give people enough interest to click on a link. An alternate subject would be "string longer than nvarchar."

Now on to your question. If you are returning a String that doesn't fit in a datatype, why not use a different datatype? In this case, a CLOB can hold more than 4000 characters.
 
gaurav kant
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry dear, in future i wll keep this in mind.
i m working on sqlserver2005,
is it possible to use CLOB ?
but anyways, i have used it like this

CallableStatement proc = conn.prepareCall(procedureString);
proc.registerOutParameter(1, Types.CLOB);
proc.execute();
Clob aclob = proc.getClob(1);
Reader charsRead= aclob.getCharacterStream();
char[] textBuffer = new char[1024];
int position = 1;
String myString="";
while ((charsRead.read(textBuffer)) != -1) {
String str=new String(textBuffer);
myString+=str;
textBuffer = new char[1024];
}
System.out.println("MyString :::::::::::: ");
wen i m printing this string , it is showing the same as it was earlier.
m i doing nything wrong?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what have you told it to print out?
 
gaurav kant
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is a huge data(more than 10,000 characters) dat i wanted to print.

lets assume dat data , comming from database is "this is complete text"

and when i m trying to print it is printing only " this is compl"

i think this problem is comming due to jdbc driver
database is returning complete text and wen i m trying to extract proc.getNString(1); it is giving exactly 4000 characters. remaining is being truncated.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic