File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes need Urgent  help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "need Urgent  help" Watch "need Urgent  help" New topic

need Urgent help

gaurav kant

Joined: Oct 06, 2008
Posts: 14
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);
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

Joined: May 26, 2003
Posts: 33117

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
gaurav kant

Joined: Oct 06, 2008
Posts: 14
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);
Clob aclob = proc.getClob(1);
Reader charsRead= aclob.getCharacterStream();
char[] textBuffer = new char[1024];
int position = 1;
String myString="";
while (( != -1) {
String str=new String(textBuffer);
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

Joined: Oct 13, 2005
Posts: 46367
And what have you told it to print out?
gaurav kant

Joined: Oct 06, 2008
Posts: 14
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.
I agree. Here's the link:
subject: need Urgent help
It's not a secret anymore!