• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1888
  • Last Modified:

insert clob into oracle table through jsp

I'm trying to insert data in clob oracle table through jsp, we use jdbc.odbc driver
tomcat 4.1.18 as our server and jdk1.3.x, oracle 9i
and I have this error:  

java.lang.ClassCastException: sun.jdbc.odbc.JdbcOdbcConnection
        at oracle.jdbc.driver.OracleConnection.physicalConnectionWithin(OracleConnection.java:5128)
        at oracle.sql.CLOB.createTemporary(CLOB.java:1010)
        at oracle.sql.CLOB.createTemporary(CLOB.java:956)

Hopefully this provide enough info, could you please tell me what is wrong with my codes?  thanks a lot for helping.
       
 
               PreparedStatement pstmt = conn.prepareStatement("insert into Notes VALUES (" + SystemID + ",'" + UserID + "',sysdate, ?);");

               oracle.sql.CLOB clob = null;
               clob = CLOB.createTemporary(pstmt.getConnection(), true, CLOB.DURATION_SESSION);
               clob.open(CLOB.MODE_READWRITE);
 
               Writer clobWriter = clob.getCharacterOutputStream();
               clobWriter.write(Comments);
               clobWriter.flush();
               clobWriter.close();
 
               clob.close();
 
               OraclePreparedStatement opstmt = (OraclePreparedStatement)pstmt;
               opstmt.setCLOB(1, clob);
0
nictran
Asked:
nictran
  • 4
1 Solution
 
bloodredsunCommented:
I think there's an error in your SQL: an extra ;

PreparedStatement pstmt = conn.prepareStatement("insert into Notes VALUES ( " + SystemID + ",'" + UserID + "',sysdate, ?)" );

Have a look at this, it seems to be a much easier way to enter a CLOB into an Oracle db

http://forum.java.sun.com/thread.jspa?threadID=349880

It's got some specific comments for Oracle 9


0
 
bloodredsunCommented:
What is the object "Comments", is it a String or a character array?
0
 
bloodredsunCommented:
and from the stacktrace, it seems that the error is in this line

  clob = CLOB.createTemporary(pstmt.getConnection(), true, CLOB.DURATION_SESSION);

try

  oracle.sql.CLOB newClob = oracle.sql.CLOB.createTemporary(conn, false, oracle.sql.CLOB.DURATION_CALL);
0
 
schybertCommented:
I'm pretty certain that you have to use the Oracle jdbc driver when using oracle.sql.CLOB.

May I ask why you are using the jdbc-odbc bridge?

'H
0
 
bloodredsunCommented:
Agreed
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now