8 Replies Latest reply on Aug 26, 2009 6:34 AM by 800781

    How to convert java.sql.blob to oracle.sql.blol

    800781

      I am migrating mysql database to oracle using java. While tring to blob a photo image i am getting the error.


      CODE:
      psmt.setBLOB(2, (BLOB)rsEnrolment.getBlob("FamilyPhotograph"));

      EXCEPTION:
      java.lang.ClassCastException: com.mysql.jdbc.Blob cannot be cast to oracle.sql.BLOB
      at com.eagle.perso.BeanMigrateMysqlToOracle.migratePhotoTable(BeanMigrateMysqlToOracle.java:134)
      at com.eagle.perso.BeanMigrateMysqlToOracle.main(BeanMigrateMysqlToOracle.java:29)

      Note : I am trying to move large amount of data . Approximately 3000000 data ..

        • 1. Re: How to convert java.sql.blob to oracle.sql.blol
          843859
          CulbOy wrote:
          I am migrating mysql database to oracle using java. While tring to blob a photo image i am getting the error.


          CODE:
          psmt.setBLOB(2, (BLOB)rsEnrolment.getBlob("FamilyPhotograph"));

          EXCEPTION:
          java.lang.ClassCastException: com.mysql.jdbc.Blob cannot be cast to oracle.sql.BLOB
          at com.eagle.perso.BeanMigrateMysqlToOracle.migratePhotoTable(BeanMigrateMysqlToOracle.java:134)
          at com.eagle.perso.BeanMigrateMysqlToOracle.main(BeanMigrateMysqlToOracle.java:29)
          You should not write JDBC driver dependent code. Just use ResultSet#getBinaryStream() and PreparedStatement#setBinaryStream().
          Note : I am trying to move large amount of data . Approximately 3000000 data ..
          Rather use the import/export tools supplied by the DB. Java isn't the right tool for this.
          • 2. Re: How to convert java.sql.blob to oracle.sql.blol
            800781
            1. Rather use the import/export tools supplied by the DB. Java isn't the right tool for this.
            • 3. Re: How to convert java.sql.blob to oracle.sql.blol
              800781
              *1.You should not write JDBC driver dependent code. Just use ResultSet#getBinaryStream() and* PreparedStatement#setBinaryStream().

              I have updated the code as per your advice , But i am getting the following error , I changed the code as :

              oracle.jdbc.OraclePreparedStatement psmt = (oracle.jdbc.OraclePreparedStatement)  
               psmt.setBinaryStream(2, rsEnrolment.getBinaryStream("FamilyPhotograph"));
              The error that i get is :
              Exception in thread "main" java.lang.AbstractMethodError: oracle.jdbc.driver.OraclePreparedStatement.setBinaryStream(ILjava/io/InputStream;)V


              +2. Rather use the import/export tools supplied by the DB. Java isn't the right tool for this.+
              I dont have any other option rather than doing it . Can you please tell what problems that i would face.
              • 4. Re: How to convert java.sql.blob to oracle.sql.blol
                843859
                CulbOy wrote:
                java.lang.AbstractMethodError
                Your classpath is polluted with duplicate jars/classes of different versions.
                +2. Rather use the import/export tools supplied by the DB. Java isn't the right tool for this.+
                I dont have any other option rather than doing it . Can you please tell what problems that i would face.
                The ease and efficiency.
                • 5. Re: How to convert java.sql.blob to oracle.sql.blob
                  800781
                  I have checked and updated the jar files, Changed all the mysql But still i am getting the same error . I am using ojdbc_14g jar and mysql-connector.jar .. Could nt sort out what probem it is ??

                  Is there any solution?
                  • 6. Re: How to convert java.sql.blob to oracle.sql.blob
                    800781
                    Tried to implement
                    java.io.OutputStream os = ((oracle.sql.BLOB) myBlob).setBinaryStream(1L);
                    But still couldnt cast oracle.sql.BLOB to mysql blob.
                    • 7. Re: How to convert java.sql.blob to oracle.sql.blob
                      843859
                      CulbOy wrote:
                      I have checked and updated the jar files, Changed all the mysql But still i am getting the same error . I am using ojdbc_14g jar and mysql-connector.jar .. Could nt sort out what probem it is ??

                      Is there any solution?
                      Ensure that those are JDBC 4.0 drivers.
                      • 8. Re: How to convert java.sql.blob to oracle.sql.blob
                        800781
                        The problem was with the jar file.. Once i changed to jdbc 4.0 compatibility ,
                        It works ..

                        Thanxx man... Its working gr8 !!!

                        Now i am testing for large data .. .
                        Thats why it took so much time for replying ..Hopefully it also works !!

                        Edited by: CulbOy on Aug 26, 2009 12:01 PM