This discussion is archived
0 Replies Latest reply: Jul 22, 2011 4:21 AM by 420476 RSS

OrdDicom and Java

420476 Newbie
Currently Being Moderated
Hello,

After going through a lot of docs, samples, dead links, manuals and other stuff, i finally managed to write java app which reads and updates objects stored in DICOM column. However, still I am not able to upload an image data into database. Code which separates the issue looks like this:


-----
import java.io.File;
import java.io.FileInputStream;
import oracle.jdbc.*;
import java.sql.*;
import oracle.ord.dicom.OrdDicom;
import oracle.ord.im.OrdImage;

public class BasicExample3 {

     public OracleConnection connect( ) throws Exception{
     
          Class.forName ("oracle.jdbc.driver.OracleDriver");
          OracleConnection con = (OracleConnection)DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","SYSTEM","********");
          con.setAutoCommit(false);
          return con;
     }

     public void runExample() {   
          try {   
               OracleConnection con = connect();
               Statement s = con.createStatement();
               CallableStatement cs = con.prepareCall("{ CALL ordsys.ord_dicom.setDataModel() }");
               cs.executeUpdate();
               OracleResultSet rs = (OracleResultSet)s.executeQuery("Select max(id_zdj) from obrazy");
               
               rs.next();
               int maxId = rs.getInt(1) + 1;
               System.out.println("Inserting empty image...");
               s.executeUpdate("insert into obrazy(id_zdj, dicom) values (" + maxId + ", ORDSYS.ORDDicom())");
               System.out.println("Empty image inserted.");
          
               rs = (OracleResultSet)s.executeQuery ("select dicom from obrazy where id_zdj = " + maxId + " for update ");
               if(rs.next()) {                
                    OrdDicom image = (OrdDicom)rs.getCustomDatum(1, OrdDicom.getFactory());
                    if(image.isLocal()) {
                         System.out.println("Image is stored locally.");
                    } else {
                         System.out.println("Image is stored externally at " + image.getSourceInformation());
                    }
          
                    if(!image.loadContent(new FileInputStream("C:\\DICOM\\dic1.dcm"), true)) {
                         System.out.println("loadContent failed!");
                         return;
                    }
                    
                    image.setProperties( );
                    OraclePreparedStatement stmt1 = (OraclePreparedStatement)
                    con.prepareCall("update obrazy set dicom = ? where id_zdj = " + maxId);
                    stmt1.setCustomDatum(1,image);
                    stmt1.execute( );
                    con.commit();
                    stmt1.close( ) ;
                    System.out.println("Seems to work.");
               
               } else {
                    System.out.println("Record not found.");
               }
          } catch(Exception e){
               e.printStackTrace();
          }
     }
     
     public static void main(String[] args){
          
          BasicExample3 example = new BasicExample3();
          example.runExample();
     }

}
-----

Please do not mind the way ID is generated, in my main application sequence is used for this. Anyway, application output is:

Inserting empty image...
Empty image inserted.
Image is stored externally at ???:/null/null
loadContent failed!

So my question is: what is wrong with approach above? All I need is to insert a record with locally stored DICOM object into database - so maybe I should use different ORDDicom constructor? Maybe creating empty image and uppdating it with data is not a correct approach?

Any help would be greatly appreciated.

Best regards,
Hobson

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points