This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi All, Am using Sybase DB and retrieve data into Java code.I have a column of type "text" and return a variable of length 300 chars to Java from the "text" field. Java uses resultset.getString("column name") to get the column's value from the result set.
The issue we have is - even if the DB returns a value of length 300 chars, java is truncating it to 255. Same is the case when tried with resultset.getObject("column name").toString().
Is there any limit on the string length returned by Result set? Is there any way to maximise / set the length of string returned from result set?
On the Java side, there is no restriction on the length of Strings (unless you want Strings which are more than 2 billion characters long). On the database side, it's quite common for a database to put limits on the length of text columns. 255 is a common limit for that.
Once the database has truncated the string, though, there is no way to repair it. Not in Java nor in the database. There are other column types which allow longer strings to be stored, so you should consider using them instead.
Joined: Jan 10, 2007
We are using BEA Sybase driver and the Sybase Table has this column as a "Text" Field which allows upto 2GB. The fact is, when we run the Stored Procedure in the DB we get the complete text without truncating to 255 chars. But when we call the Stored proc from Java code using JDBC, the resultset.getString() truncates it to 255. I wonder whether this is an issue with JDBC.
Try retrieving data as Clob/Blob (i.e. stream). Further if there is no limit imposed on the table schema, check for Statement.getMaxFieldSize in your code whether or not you are applying a limit on the retrieval size
But I tried setting the MaxFieldSize to 300.It was defaulted to 0 earlier. Even after this , I do see only 255 chars in the resultset returned from Sybase to Java. I tried to retrieve it as an Object instead of a String. But again, in vein.