Jitu
asked on
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 ?
Thanks
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 ?
Thanks
ASKER
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.
So,
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....
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.
So,
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....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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...?
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...?
ASKER
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.getCharacterOutputStr eam();
int i = 0;
//s is the string that holds the data
int length = s.length();
int chunk = length;
outstream.write(s, 0, chunk);
outstream.close();
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.getCharacterOutputStr
int i = 0;
//s is the string that holds the data
int length = s.length();
int chunk = length;
outstream.write(s, 0, chunk);
outstream.close();
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.