13 messages in com.mysql.lists.javaRe: CLOB question ...| From | Sent On | Attachments |
|---|---|---|
| Jeff Mathis | 22 Aug 2003 10:06 | |
| Mark Matthews | 22 Aug 2003 13:19 | |
| Jeff Mathis | 22 Aug 2003 13:23 | |
| Mufaddal Khumri | 24 Sep 2003 22:42 | |
| Mufaddal Khumri | 25 Sep 2003 00:00 | |
| Mufaddal Khumri | 25 Sep 2003 01:53 | |
| John Beveridge | 25 Sep 2003 15:16 | |
| Jeff Mathis | 30 Sep 2003 12:27 | |
| Mufaddal Khumri | 08 Oct 2003 21:25 | |
| Mufaddal Khumri | 08 Oct 2003 21:36 | |
| Dirk Hillbrecht | 09 Oct 2003 09:57 | |
| Dirk Hillbrecht | 09 Oct 2003 10:16 | |
| Fouche du Preez | 14 Oct 2003 02:25 |
| Subject: | Re: CLOB question ...![]() |
|---|---|
| From: | Mufaddal Khumri (mufa...@wmotion.com) |
| Date: | 09/25/2003 12:00:39 AM |
| List: | com.mysql.lists.java |
Hi,
I made a few corrections and changes to the code that i had sent earlier. I want to store a huge java String as a CLOB in the MYSQL Database.
I have a table defined like this: CREATE TABLE CLOBTEST (ID INTEGER NOT NULL AUTO_INCREMENT, DESCRIPTION TEXT, PRIMARY KEY (ID)) TYPE = innoDB;
Next I do this: PreparedStatement pstmt1 = con.prepareStatement("INSERT INTO CLOBTEST " + "(ID) VALUES (?))"); pstmt1.setInt(1, 2); pstmt1.executeUpdate(); pstmt1.close();
After this I do this to get the clob objects:
Statement stmt = con.createStatement();
ResultSet rs1 = stmt.executeQuery("SELECT DESCRIPTION from CLOBTEST");
Vector v = new Vector(); while(rs1.next()) v.addElement(rs1.getClob("DESCRIPTION"));
rs1.close(); stmt.close();
Once i have got the clob object, i want to write some data in the clob object from a java string and store the clob to the database
PreparedStatement pstmt = con.prepareStatement("INSERT INTO CLOBTEST " + "(DESCRIPTION) VALUES (?)"); if(v != null && v.isEmpty() == false) { System.out.println("Inside if statement.");
Clob c = (Clob)v.elementAt(0); c.setString(1, " Hello World ");
pstmt.setClob(1, c); pstmt.executeUpdate(); }
pstmt.close();
I get the following exception:
java.lang.NullPointerException at java.lang.StringBuffer.<init>(StringBuffer.java:130) at com.mysql.jdbc.Clob.setString(Clob.java:123) at ClobTest.main(ClobTest.java:43)
I need to store a java String inside a Clob object.
Thanks.




