Clob problem

Hi:

Java Strings can only hold 4000 characters, so I cannot use a String.

I have incoming data of over 4000 characters in a textarea on a webpage that I need to move data into a Clob in a database. How would I go about doing this? Keep it simple. I am new.

Please help me,

Rachel K

[313 byte] By [Rachel_Ka] at [2007-11-26 20:49:22]
# 1
Actually, a String can hold 65536 characters.
Djaunla at 2007-7-10 2:13:12 > top of Java-index,Java Essentials,New To Java...
# 2
I would repost this to the jdbc forum ... I have seen one or so recent posts on this topic there as well if I remember right.Check out this thread (specifically krunals post #1): http://forum.java.sun.com/thread.jspa?threadID=5143945&tstart=0
abillconsla at 2007-7-10 2:13:12 > top of Java-index,Java Essentials,New To Java...
# 3

> Actually, a String can hold 65536 characters.

public class StringExample {

public static void main(String[] args) {

String s = "?";

while (true) {

System.out.println(s.length());

s += s;

}

}

}

Result?

DrLaszloJamfa at 2007-7-10 2:13:12 > top of Java-index,Java Essentials,New To Java...
# 4

> > Actually, a String can hold 65536 characters.

> > public class StringExample {

>public static void main(String[] args) {

>String s = "?";

>while (true) {

> System.out.println(s.length());

>s += s;

>}

> }

> }

>

> Result?

OutOfMemory at around 2^21. Guess the thread I found that said 2^16 was outdated or wrong or something.

Djaunla at 2007-7-10 2:13:12 > top of Java-index,Java Essentials,New To Java...
# 5
64K is probably the limit on a string literal such as String s = "abc";The limit should be Integer.MAX_VALUE forString s = getItFromSomewhere();The 2^21 limit may have something to do with the heap size.
baftosa at 2007-7-10 2:13:12 > top of Java-index,Java Essentials,New To Java...
# 6
Think the OP means:[url http://www.ss64.com/orasyntax/datatypes.html]Oracle Data Types[/url]
abillconsla at 2007-7-10 2:13:12 > top of Java-index,Java Essentials,New To Java...
# 7

> I would repost this to the jdbc forum ... I have seen

> one or so recent posts on this topic there as well if

> I remember right.

>

> Check out this thread (specifically krunals post #1):

> http://forum.java.sun.com/thread.jspa?threadID=5143945&tstart=0

I notice that in 1.6, PreparedStatement has new methods:

void setClob(int parameterIndex, Reader reader)

and

void setClob(int parameterIndex, Reader reader, long length)

DrLaszloJamfa at 2007-7-10 2:13:12 > top of Java-index,Java Essentials,New To Java...
# 8

Regardless of how many characters a String holds I still need to get my input into a Clob. The String cannot hold as many characters as a Clob and my input is failing. I need help for my problem, not platitudes on how many characters a String can hold. I need to know how to move my data from a textarea into a Clob.

Rachel_Ka at 2007-7-10 2:13:12 > top of Java-index,Java Essentials,New To Java...
# 9

> Regardless of how many characters a String holds I

> still need to get my input into a Clob. The String

> cannot hold as many characters as a Clob and my input

> is failing. I need help for my problem, not

> platitudes on how many characters a String can hold.

> I need to know how to move my data from a textarea

> into a Clob.

1) If you're actually getting your data from a java.awt.TextArea or a javax.swing.JTextArea, then you're getting a java.lang.String. Therefore, you shouldn't be worried that it can't hold as many characters as you need to write.

2) If your database actually contains a CLOB, then you can use PreparedStatement.setCharacterStream() to set the value. This may not be obvious, and looking at DrLaszloJamf's reply, it seems that the API designers thought so as well.

3) Since you're talking about a 4000 character limit, it's very likely that your database doesn't actually specify a CLOB, but actually specifies a VARCHAR column. Check this before getting snitty.

Captain.Obviousa at 2007-7-10 2:13:12 > top of Java-index,Java Essentials,New To Java...
# 10

> Regardless of how many characters a String holds I

> still need to get my input into a Clob. The String

> cannot hold as many characters as a Clob and my input

> is failing. I need help for my problem, not

> platitudes on how many characters a String can hold.

> I need to know how to move my data from a textarea

> into a Clob.

REPLY #2!

abillconsla at 2007-7-10 2:13:12 > top of Java-index,Java Essentials,New To Java...
# 11

> > Regardless of how many characters a String holds I

> > still need to get my input into a Clob. The

> String

> > cannot hold as many characters as a Clob and my

> input

> > is failing. I need help for my problem, not

> > platitudes on how many characters a String can

> hold.

> > I need to know how to move my data from a textarea

> > into a Clob.

>

> 1) If you're actually getting your data from a

> java.awt.TextArea or a

> javax.swing.JTextArea, then you're getting a

> java.lang.String. Therefore, you shouldn't be

> worried that it can't hold as many characters as you

> need to write.

>

> 2) If your database actually contains a CLOB, then

> you can use

> PreparedStatement.setCharacterStream() to set

> the value. This may not be obvious, and looking at

> DrLaszloJamf's reply, it seems that the API

> designers thought so as well.

>

> 3) Since you're talking about a 4000 character limit,

> it's very likely that your database doesn't

> actually specify a CLOB, but actually specifies a

> VARCHAR column. Check this before getting snitty.

Unless I am very much mistaken, it's the DB that she is stating is the limiting factor or 4000 on a varchar2. Whether that is the case or not, for whatever reason she wants or needs or both to load into a Clob. But you are right ... she should not be getting snitty. ;o)

abillconsla at 2007-7-10 2:13:12 > top of Java-index,Java Essentials,New To Java...