Long datatype

I have a table test1 in Oracle8i with the one of the columns (c2) as Long.

After getting the recordset like this :

Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select c2 from test1");

when i do

while (rs.next()) {
  long myVal = rs.getLong(1)

I get a runtime error which says :
Fail to convert internal representation: getLong.

Why is this so.. i thought this was the right way to get value of a Long datatype column.

But instead when i modify that statement to :

String myVal = rs.getString(1);

This works fine, without any errors.
But, why ?


What abt columns which are clob in the database. After i read them in like this :

Clob c = rs.getClob(1)

How do i get the String (data) out of clob ?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


1.  Long column support will be discontinued in a future Oracle release per the Getting to Know Oracle8i document (migrate to LOB is recommended)

2.  Java's long is equivalent to Oracle's BIGINT

3.   Oracle8i's LONG is is really a LONGVARCHAR, that is a very long character variable.  Nothing to do with a 64 bit integer.  They suggest standarad jdbc type is AsciiStream or Unicode Stream (sqlj.runtine classes).  See Oracle8i SQLJ Developer's Guide and Reference.

4.  So you can't do a java getLong on something that is a string.  If it really is a string representation of a 64 bit integer, then I would think you need to retrieve it as a string, then convert it to a long.

As far as getting data out of CLOB's, see the same manual for some examples.
It looks like one can almost treat a CLOB as a String -- at least it has a length method and a getSubString method.
JituAuthor Commented:
refactor >
Thanks. I have found how to read a clob column from database, using examples in Oracle documentation. They use oracle.sql package.

But, all the examples for inserting into a clob column talk of reading clob from somwhere (like another table or some inline .dat file) and inserting.
This is not applicable to me.

How do i insert a value in a column that is of type Clob in the database.

What i mean is i first declare a variable of type

oracle.sql.CLOB c
//This package oracle.sql is part of the oracle thin driver zip.

//Now what is the constructor for CLOB
//how do i add data/characters to this clob.

and then use setClob etc... to set the value in PreparedStatement.

What is the constructor of CLOB of Oracle.sql package ? Where can i find documentation for this....

CLOB itself is an interface.

For documentation in general, which is probably not new news to you:

JDBC documentation references CLOB's
jdk1.2.2\docs\api\index.html, under java.sql package shows the clob interface and some methods for it.  

The oracle documenation apparently adds to this.

From Oracle8i Application Developer's Guide - Large Objects (LOBs)
Release 2 (8.1.6)

look at LOB Programmatic Environments, 9 of 9, Using Java (JDBC) to work with LOBs.  This has a number of tables with methods for each of the different LOBs.

Example from one of the tables.
int putString(long, java.lang.String)
 Inserts the string into the LOB, starting at the given offset  
int putChars(long, char[])
 Inserts the character array into the LOB, starting at the given offset

To mess with a CLOB, you need a handle on such an object. From your note, it sounds like you already have such, and then would use the appropriate methods.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JituAuthor Commented:
refractor >
Thanks that was helpful.

But, i am still having one problem :

The data i have to insert is in a String :

String myData = ".." // This is a huge string around 5000 characters.

//After getting the handle of the clob, i do a putString like this :

myClob.putString(1, myData);

//This gives an error msg on running i.e :

Data size bigger than max size for this type : 5004

If i reduce the size of the string to 4000 charactes or less, it works fine.

Why is this... the clob column is behaving as if it were varchar2(4000)

If i am not able to insert anything more than 4000 chars, then what is the use of clob.

Probably i am doing it wrong or missing something...? Any inputs...?
JituAuthor Commented:
refractor >

i have got round the problem i mentioned in my previous comment. I am using the following way to add data now, and it works fine for large data:

 Writer outstream = clob.getCharacterOutputStream();
        int i = 0;
//s is the string that holds the data

      int length = s.length();

      int chunk = length;

      outstream.write(s, 0, chunk);
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.