sdesar
asked on
How to get size of the String using the Reader?
How can I change this code so its gets the size of the string? Currently I get the length of the buffer
and it prints is many times, ie 32K
How can I modify the for loop may be use while loop to get the length of the string and write it CLOB?
Here's the entire code.....
public void writeStringToClob(int i_issue_id, String s_description) {
Connection x_conn = (Connection) ox_pool.checkout ();
Statement x_stmt = null;
s_description = "TEST THE 4000 character limit";
cdebug.println ("\n\nTESTING: " + s_description);
try {
x_conn.setAutoCommit(false );
x_stmt = x_conn.createStatement();
// cdebug.println("x_statment : " + x_stmt.toString());
ResultSet l_lobDetails = x_stmt.executeQuery(
"SELECT DESCR FROM ISSUE WHERE ISSUEID="+ Integer.toString ( i_issue_id ) + " FOR UPDATE");
// load the rest of the description into the Clob Column
if ( l_lobDetails.next() )
{
Clob l_clobDescr = l_lobDetails.getClob(1);
Writer l_clobWriter = ( (oracle.sql.CLOB)l_clobDes cr).getCha racterOutp utStream() ;
cdebug.println ("TESTING GET CLOB: " + l_lobDetails.getClob(1));
// java.io.Reader l_clobStream = l_clobDescr.getCharacterSt ream();
//Read from Char Stream and write to Clob Stream
char[] l_buffer = new char[10*1024]; // buffer holding the characters being transferred
l_buffer = s_description.toCharArray( );
for (int i = 0; i<l_buffer.length; i++){ // Read from StringBuffer
cdebug.println (" GOT BUFFER: " + l_buffer[i]);
l_clobWriter.write(l_buffe r,0,l_buff er.length) ; // Write to Clob
}
//cdebug.println ("Result: " + l_clobDescr);
// l_clobStream.close(); // close reader
l_clobWriter.close(); // close writer
}
l_lobDetails.close(); // close resultset
x_stmt.close(); // close statement
x_conn.close(); // close connection
} catch (Exception ex) {
cdebug.println ( "GtsNewIssue writeStringToClob caught error in getting the String");
cdebug.println ("GtsNewIssue caught error: " + ex.toString() );
}
ox_pool.checkin ( x_conn );
}
Awaiting a response,
Thanks.
and it prints is many times, ie 32K
How can I modify the for loop may be use while loop to get the length of the string and write it CLOB?
Here's the entire code.....
public void writeStringToClob(int i_issue_id, String s_description) {
Connection x_conn = (Connection) ox_pool.checkout ();
Statement x_stmt = null;
s_description = "TEST THE 4000 character limit";
cdebug.println ("\n\nTESTING: " + s_description);
try {
x_conn.setAutoCommit(false
x_stmt = x_conn.createStatement();
// cdebug.println("x_statment
ResultSet l_lobDetails = x_stmt.executeQuery(
"SELECT DESCR FROM ISSUE WHERE ISSUEID="+ Integer.toString ( i_issue_id ) + " FOR UPDATE");
// load the rest of the description into the Clob Column
if ( l_lobDetails.next() )
{
Clob l_clobDescr = l_lobDetails.getClob(1);
Writer l_clobWriter = ( (oracle.sql.CLOB)l_clobDes
cdebug.println ("TESTING GET CLOB: " + l_lobDetails.getClob(1));
// java.io.Reader l_clobStream = l_clobDescr.getCharacterSt
//Read from Char Stream and write to Clob Stream
char[] l_buffer = new char[10*1024]; // buffer holding the characters being transferred
l_buffer = s_description.toCharArray(
for (int i = 0; i<l_buffer.length; i++){ // Read from StringBuffer
cdebug.println (" GOT BUFFER: " + l_buffer[i]);
l_clobWriter.write(l_buffe
}
//cdebug.println ("Result: " + l_clobDescr);
// l_clobStream.close(); // close reader
l_clobWriter.close(); // close writer
}
l_lobDetails.close(); // close resultset
x_stmt.close(); // close statement
x_conn.close(); // close connection
} catch (Exception ex) {
cdebug.println ( "GtsNewIssue writeStringToClob caught error in getting the String");
cdebug.println ("GtsNewIssue caught error: " + ex.toString() );
}
ox_pool.checkin ( x_conn );
}
Awaiting a response,
Thanks.
Also if the above is correct then you really don't need the loop at all.
ASKER
Yes ,I need to get the length of the description which is converted to a characterArray.
What should I dO?
What should I dO?
ASKER
Yes ,I need to get the length of the description which is converted to a characterArray.
What should I dO?
What should I dO?
ASKER
Yes ,I need to get the length of the description which is converted to a characterArray.
What should I dO?
What should I dO?
See my original answert then. Also why are you then looping through the array?
I think this should do it:
Replace
for (int i = 0; i<l_buffer.length; i++){ // Read from StringBuffer
cdebug.println (" GOT BUFFER: " + l_buffer[i]);
l_clobWriter.write(l_buffe r,0,l_buff er.length) ; // Write to Clob
}
with
l_clobWriter.write(l_buffe r,0,s_desc ription()) ;
-matty
I think this should do it:
Replace
for (int i = 0; i<l_buffer.length; i++){ // Read from StringBuffer
cdebug.println (" GOT BUFFER: " + l_buffer[i]);
l_clobWriter.write(l_buffe
}
with
l_clobWriter.write(l_buffe
-matty
ASKER
But, s_description is not a method. Its a string.
ASKER
Also, I need some loop to loop through the CharacterArray
.. isn't it?
.. isn't it?
Yes but it's a string object and one of it's methods is length().
Take a look at
http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html#length()
hope this helps!
Matty
Take a look at
http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html#length()
hope this helps!
Matty
The only thing your character array does is call the same method over and ove r agin passing it the same values. If you could describe what you expect to happen in the loop I would happy to help you fix it up!
ASKER
I know that I can get the length of the String. But I need to get the CharacterArray 's size
ASKER
The main reason for the bove routine is becuse in ORACLE there is a 2 k limit on String literal.
So I have writen this method above which does the following-
Converts the Clob into String which is then converted to a
Character Array.
So I have writen this method above which does the following-
Converts the Clob into String which is then converted to a
Character Array.
ASKER
I then need either a While or a for loop to read in the
Characters and write also.
Awaiting a response!
Thanks for helping me.
Characters and write also.
Awaiting a response!
Thanks for helping me.
Alright think I understand. I think your code is correct but this
l_clobWriter.write(l_buffe r,0,l_buff er.length) ; // Write to Clob
should be moved out of the for loop. So your code would do the follwing then
1. Convert Clob to a String
2. Convert the Strng to a char[]
3. Loop and print each char[]
4. Write the char[] to the Clob_writer stream
-matty
l_clobWriter.write(l_buffe
should be moved out of the for loop. So your code would do the follwing then
1. Convert Clob to a String
2. Convert the Strng to a char[]
3. Loop and print each char[]
4. Write the char[] to the Clob_writer stream
-matty
ASKER
Can you please show me how to code steps 3 and 4.
ASKER
I have written the code for steps 1 and 2.
But I don't understand how to loop? what should I use
for, while etc..
But I don't understand how to loop? what should I use
for, while etc..
ASKER
Currently, the way the code is written.. It loops 32 times, upto 32 K !
That's not good. Thereofore, I would like io know what's a better way to do it!
Thanks
That's not good. Thereofore, I would like io know what's a better way to do it!
Thanks
That's crrect it loops each time because of tthis statement:
cdebug.println (" GOT BUFFER: " + l_buffer[i]);
this loop reads one character at a time from the array and prints it. Is this necessary?
cdebug.println (" GOT BUFFER: " + l_buffer[i]);
this loop reads one character at a time from the array and prints it. Is this necessary?
ASKER
No its not necessary.. I was using it for debugging purposes only.
Right okay so then you shoudln't need to loop as you are passing in the entire char[] array. So in my original list
1. Convert Clob to a String
2. Convert the Strng to a char[]
3. Loop and print each char[]
4. Write the char[] to the Clob_writer stream
point three is really not needed. As such your code should be as I stated before:
Replace
for (int i = 0; i<l_buffer.length; i++){ // Read from StringBuffer
cdebug.println (" GOT BUFFER: " + l_buffer[i]);
l_clobWriter.write(l_buffe r,0,l_buff er.length) ; // Write to Clob
}
with
l_clobWriter.write(l_buffe r,0,s_desc ription()) ;
1. Convert Clob to a String
2. Convert the Strng to a char[]
3. Loop and print each char[]
4. Write the char[] to the Clob_writer stream
point three is really not needed. As such your code should be as I stated before:
Replace
for (int i = 0; i<l_buffer.length; i++){ // Read from StringBuffer
cdebug.println (" GOT BUFFER: " + l_buffer[i]);
l_clobWriter.write(l_buffe
}
with
l_clobWriter.write(l_buffe
ASKER
I removed the for loop and added -
l_clobWriter.write(l_buffe r,0,s_desc ription()) ;
I compiled it and got this error-
Reference to variable s_description in class GtsNewIssue
as if it were a method.
l_clobWriter.write(l_buffe
I compiled it and got this error-
Reference to variable s_description in class GtsNewIssue
as if it were a method.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried:-
l_clobWriter.write(l_buffe r,0,s_desc ription.le ngth());
But, I still got the Oracle error !
That is if I insert > 4000 character the Entire string failed to insert.
How can I get the chunk / block size so it writes to that block?
I think I need some sort of a loop to loop through those characters in the array.
l_clobWriter.write(l_buffe
But, I still got the Oracle error !
That is if I insert > 4000 character the Entire string failed to insert.
How can I get the chunk / block size so it writes to that block?
I think I need some sort of a loop to loop through those characters in the array.
ASKER
awaiting more suggestions!
l_clobWriter.write(l_buffe
would instead be
l_clobWriter.write(l_buffe
is this what you were aiming for?
-mattyk