Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.sql.SQLException Fail to convert to internal representation

MagwaaOct 16 2015 — edited Feb 11 2016

Hello all,

I am working on web services in Jdeveloper. I am using a Java method which calls a specific procedure to select the data from source and then another method pass this data on to the destination.Everything is working fine except when it comes to inserting a BLOB file in the database. The data selected is a whole record and stored in Object[]. The method is as follows:

private Object\[\] getRecordObject(Connection conn, String recordType, ArrayList\<String> dataList,

                                 String parsingAlgo) {

    long objStartTime = System.currentTimeMillis();

    Object\[\] recordobjects = new Object\[dataList.size()\];

    try {

        StructDescriptor cptrecord = StructDescriptor.createDescriptor(recordType, conn);

        //System.out.println("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*");

        //    System.out.println("In getRecordObject funcation list data is " + dataList.size());

        // System.out.println("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*");

        StringTokenizer algotokenizer = new StringTokenizer(parsingAlgo, ",");

        String columnSplitter = "~~~";

        String recordSplitter = "####";

        //  System.out.println("parsing algorithm is " + parsingAlgo);

        if (algotokenizer.countTokens() == 2) {

            columnSplitter = algotokenizer.nextToken();

            recordSplitter = algotokenizer.nextToken();

        }

        for (int i = 0; i \< dataList.size(); i++) {

            //    System.out.println("loop continue " + i);

            String recorddata = dataList.get(i);

            Pattern pattern = Pattern.compile(recordSplitter);

            String\[\] allrecords = pattern.split(recorddata);

            Object\[\] structdata = new Object\[allrecords.length\];

            int count = 0;

            for (String element : allrecords) {

                String record = element;

                //System.out.println("record is " + record);

                Pattern pattern2 = Pattern.compile(columnSplitter);

                String\[\] columnsList = pattern2.split(record);

                String colunmname = columnsList\[0\];

                String columntype = columnsList\[1\];

                String columndata = columnsList\[2\];

                if (columndata.trim().equalsIgnoreCase("empty")) {

                    columndata = "";

                    if (columntype.equalsIgnoreCase("DATE")) {

                        columndata = null;

                    }

                    if (columntype.equalsIgnoreCase("TIMESTAMP")) {

                        columndata = null;

                    }

                }

                if (columntype.equalsIgnoreCase("BLOB")) {

                    System.out.println("Column type is BLOB on destination Side");

                    String imageString = columndata;

                    //System.out.println("String Image Data is " +imageString);

                    byte\[\] imageData = imageString.getBytes();

                    BufferedImage img = decodeToImage(imageString);

                    if (img == null) {

                        System.out.println("Image is NULL");

                    }

                    System.out.println("Image is not Null");

                    try {

                        structdata\[count\] = imageData;

                        System.out.println("Struct Data Added");

                    } catch (Exception e) {

                        // TODO: Add catch code

                        structdata\[count\] = 0;

                    }

                } else if (columntype.equalsIgnoreCase("NUMBER")) {

                    try {

                        int newnum = Integer.parseInt(columndata);

                        structdata\[count\] = columndata;

                    } catch (Exception e) {

                        // TODO: Add catch code

                        structdata\[count\] = 0;

                    }

                } else if (columntype.equalsIgnoreCase("CHAR")) {

                    //System.out.println(" column data for char type have name "+colunmname+" is "+columndata);

                    structdata\[count\] = columndata;

                } else if (columntype.equalsIgnoreCase("VARCHAR2")) {

                    structdata\[count\] = columndata;

                } else {

                    structdata\[count\] = columndata;

                }

                count++;

            }

            System.out.println("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*");

            System.out.println("Before System Exit");

            System.out.println("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*");

           **STRUCT m = new STRUCT(cptrecord, conn, structdata);**

            System.out.println("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*");

            System.out.println("Hoorah!!");

            System.out.println("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*");

            System.exit(0);

            recordobjects\[i\] = m;

        }

    } catch (Exception sqle) {

        System.out.println("in record group exception ");

        // TODO: Add catch code

        dataList.clear();

        this.registerException(dataList, sqle.getMessage());

        sqle.printStackTrace();

    }

    long objEndTime = System.currentTimeMillis();

    System.out.println("Time taken to construct object array is " + (objEndTime - objStartTime) / 1000);

    return recordobjects;

}

The exception is raised at STRUCT m = new STRUCT(cptrecord, conn, structdata); this line.

This is the exception logged at weblogic console.

Exception.png

Can anyone please guide me ?
Regards,

--Magwaa

This post has been answered by unknown-7404 on Oct 16 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 10 2016
Added on Oct 16 2015
2 comments
8,614 views