How do i get clob data using java and assign to a variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kanthi84
    New Member
    • Feb 2007
    • 37

    #16
    Properties props = new Properties();
    props.put("SetB igStringTryClob ", "true");
    pstmt=con.prepa reStatement("IN SERT INTO TABLE values('','','' ,?,'','','')");
    pstmt.executeUp date();
    pstmt.close();
    pstmt.setString (4, lstr_points);
    pstmt.executeUp date();

    CAN U TELL ME WAT IS WRONG IN THE CODE. THE QUERY IS NOT EXCECUTING.

    THANKS IN ADVANCE

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #17
      Originally posted by kanthi84
      Properties props = new Properties();
      props.put("SetB igStringTryClob ", "true");
      pstmt=con.prepa reStatement("IN SERT INTO TABLE values('','','' ,?,'','','')");
      pstmt.executeUp date();
      pstmt.close();
      pstmt.setString (4, lstr_points);
      pstmt.executeUp date();

      CAN U TELL ME WAT IS WRONG IN THE CODE. THE QUERY IS NOT EXCECUTING.

      THANKS IN ADVANCE
      Are you getting any exception? How are you handling the exceptions?

      Comment

      • kanthi84
        New Member
        • Feb 2007
        • 37

        #18
        catch (SQLException sqlex) {
        // Catch Exceptions and display messages accordingly.
        System.out.prin tln("SQLExcepti on while connecting and inserting into " +
        "the database table: " + sqlex.toString( ));
        } catch (Exception ex) {
        System.out.prin tln("Exception while connecting and inserting into the" +
        " database table: " + ex.toString());
        }


        THE PROBLEM IS THE QUERY IS NOT EXECUTING

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #19
          Originally posted by kanthi84
          catch (SQLException sqlex) {
          // Catch Exceptions and display messages accordingly.
          System.out.prin tln("SQLExcepti on while connecting and inserting into " +
          "the database table: " + sqlex.toString( ));
          } catch (Exception ex) {
          System.out.prin tln("Exception while connecting and inserting into the" +
          " database table: " + ex.toString());
          }


          THE PROBLEM IS THE QUERY IS NOT EXECUTING
          So what happens when you run the code?
          No exception?
          And when you check in the database do you see nothing or do you see something else inserted instead?

          Comment

          • kanthi84
            New Member
            • Feb 2007
            • 37

            #20
            Exception I Am Getting Is

            Exception In Connection And Insertion
            And No Data Is Inserted Into The Database

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #21
              Originally posted by kanthi84
              Exception I Am Getting Is

              Exception In Connection And Insertion
              And No Data Is Inserted Into The Database
              Post the full exception trace.

              Comment

              • kanthi84
                New Member
                • Feb 2007
                • 37

                #22
                hi
                atlast got the solution

                i dint know that only upto 4000 characters can be saved as clob.

                that was the problem.
                when i gave less than the limit, a new row was inserted and i was able to retrieve the data as u said earlier

                thanks

                Comment

                • kanthi84
                  New Member
                  • Feb 2007
                  • 37

                  #23
                  but i have a doubt
                  i got the information from net than

                  Maximum length of CLOB (in bytes) is 2 147 483 647 and this is the same for blob also.

                  now the doubt comes

                  i am not able to insert data into clob, which i successfully uploaded using blob.
                  how can this happen if they have the same size limit?



                  thanks in advance

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #24
                    Originally posted by kanthi84
                    but i have a doubt
                    i got the information from net than

                    Maximum length of CLOB (in bytes) is 2 147 483 647 and this is the same for blob also.

                    now the doubt comes

                    i am not able to insert data into clob, which i successfully uploaded using blob.
                    how can this happen if they have the same size limit?



                    thanks in advance
                    Maybe the way you are inserting the data is incorrect?

                    Comment

                    • kanthi84
                      New Member
                      • Feb 2007
                      • 37

                      #25
                      ok.

                      i will try and will let u know what is the problem, if i get

                      anyway,thanks

                      Comment

                      • kanthi84
                        New Member
                        • Feb 2007
                        • 37

                        #26
                        hi good morning

                        it seems only less number of characters can be inserted directly into clob columb.
                        but, if we use a stored procedure to insert into clob more data can be inserted.
                        i am not aware of writing a stored procedure..


                        can anyone help me with a sample

                        thanks in advance

                        Comment

                        • kanthi84
                          New Member
                          • Feb 2007
                          • 37

                          #27
                          CAN ANYONE TELL ME THE USE OF THIS CODE?




                          import oracle.sql.CLOB ;
                          import java.sql.Connec tion;
                          import java.sql.SQLExc eption;
                          import java.io.Writer;
                          ...

                          private CLOB getCLOB(String xmlData, Connection conn) throws SQLException{
                          CLOB tempClob = null;
                          try{
                          // If the temporary CLOB has not yet been created, create new
                          tempClob = CLOB.createTemp orary(conn, true, CLOB.DURATION_S ESSION);

                          // Open the temporary CLOB in readwrite mode to enable writing
                          tempClob.open(C LOB.MODE_READWR ITE);
                          // Get the output stream to write
                          Writer tempClobWriter = tempClob.getCha racterOutputStr eam();
                          // Write the data into the temporary CLOB
                          tempClobWriter. write(xmlData);

                          // Flush and close the stream
                          tempClobWriter. flush();
                          tempClobWriter. close();

                          // Close the temporary CLOB
                          tempClob.close( );
                          } catch(SQLExcept ion sqlexp){
                          tempClob.freeTe mporary();
                          sqlexp.printSta ckTrace();
                          } catch(Exception exp){
                          tempClob.freeTe mporary();
                          exp.printStackT race();
                          }
                          return tempClob;


                          THANKS IN ADVANCE

                          Comment

                          • r035198x
                            MVP
                            • Sep 2006
                            • 13225

                            #28
                            Originally posted by kanthi84
                            CAN ANYONE TELL ME THE USE OF THIS CODE?




                            import oracle.sql.CLOB ;
                            import java.sql.Connec tion;
                            import java.sql.SQLExc eption;
                            import java.io.Writer;
                            ...

                            private CLOB getCLOB(String xmlData, Connection conn) throws SQLException{
                            CLOB tempClob = null;
                            try{
                            // If the temporary CLOB has not yet been created, create new
                            tempClob = CLOB.createTemp orary(conn, true, CLOB.DURATION_S ESSION);

                            // Open the temporary CLOB in readwrite mode to enable writing
                            tempClob.open(C LOB.MODE_READWR ITE);
                            // Get the output stream to write
                            Writer tempClobWriter = tempClob.getCha racterOutputStr eam();
                            // Write the data into the temporary CLOB
                            tempClobWriter. write(xmlData);

                            // Flush and close the stream
                            tempClobWriter. flush();
                            tempClobWriter. close();

                            // Close the temporary CLOB
                            tempClob.close( );
                            } catch(SQLExcept ion sqlexp){
                            tempClob.freeTe mporary();
                            sqlexp.printSta ckTrace();
                            } catch(Exception exp){
                            tempClob.freeTe mporary();
                            exp.printStackT race();
                            }
                            return tempClob;


                            THANKS IN ADVANCE
                            Where did you get it from? You should have asked there what they wanted to do with it.

                            Comment

                            • kanthi84
                              New Member
                              • Feb 2007
                              • 37

                              #29
                              I Got It While Searching In Google.

                              It Is To Store The String To Be Inserted Into Clob Column In A Temporary Clob. And This Can Be Inserted.
                              The Main Advantage Is That , By Using This, I Heard We Can Store Large No Of Characters Than Inserting Directly

                              Comment

                              • kanthi84
                                New Member
                                • Feb 2007
                                • 37

                                #30
                                CAN U TELL ME WAT IS WRONG WITH THE CODE.
                                THE CODE IS NOT EXECUTING


                                pstmt=con.prepa reStatement("IN SERT INTO TABLE values('','','' ,?,'','','')");
                                oracle.sql.CLOB newClob =oracle.sql.CLO B.createTempora ry(con, false, oracle.sql.CLOB .DURATION_CALL) ;
                                newClob.putStri ng(1,VALUE);
                                pstmt.setClob(4 , newClob);
                                int rowcnt = pstmt.executeUp date();

                                THANK U IN ADVANCE

                                Comment

                                Working...