File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes need Urgent  help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "need Urgent  help" Watch "need Urgent  help" New topic
Author

need Urgent help

gaurav kant
Greenhorn

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);
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
gaurav kant
Greenhorn

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);
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

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

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: http://aspose.com/file-tools
 
subject: need Urgent help
 
Similar Threads
org.hibernate.MappingException: No Dialect mapping for JDBC type: -9
Row Size Problem
Storing Kanji charaters into database
ntext problem
SQL Server + PreparedStatement Oddity