AnsweredAssumed Answered

Error while writing to PI using Java class

Question asked by ujjwal on May 8, 2018
Latest reply on May 21, 2018 by rschmitz

Hi,

 

I am using a java class to write data to PI system. The java class is called using an R script and the data is sent to the class file from R.

Please find below the code snippets.

Rscript:

"

try({

      classname="my_class"

    .jinit("<path to class>")

    obj=.jnew(classname)

    var=t(as.matrix(pidata))

    res=.jcall(obj,"S",method = "name","my_DAS","PI_server",var)

})

"

However, when i try to run this script i get the following error:

 

"

*** Error in `/opt/r/R-3.4.1/lib64/R/bin/exec/R': double free or corruption (!prev): 0x000000000add90a0 ***

======= Backtrace: =========

/lib64/libc.so.6(+0x7c619)[0x7f4b9b908619]

/opt/pipc/jdbc/lib/libRdsaWrapper64-1.5b.so(_ZNSt10unique_ptrI10NativeRDSASt14default_deleteIS0_EED1Ev+0x21)[0x7f4b28580951]

/lib64/libc.so.6(+0x38a69)[0x7f4b9b8c4a69]

/lib64/libc.so.6(+0x38ab5)[0x7f4b9b8c4ab5]

/opt/r/R-3.4.1/lib64/R/lib/libR.so(+0x20b11b)[0x7f4b9c4c911b]

/opt/r/R-3.4.1/lib64/R/lib/libR.so(run_Rmainloop+0x7b)[0x7f4b9c404efb]

/opt/r/R-3.4.1/lib64/R/bin/exec/R(main+0x1b)[0x40080b]

/lib64/libc.so.6(__libc_start_main+0xf5)[0x7f4b9b8adc05]

/opt/r/R-3.4.1/lib64/R/bin/exec/R[0x40083b]

======= Memory map: ========

00400000-00401000 r-xp 00000000 f9:00 806308                             /opt/r/R-3.4.1/lib64/R/bin/exec/R

00600000-00601000 r--p 00000000 f9:00 806308                             /opt/r/R-3.4.1/lib64/R/bin/exec/R

00601000-00602000 rw-p 00001000 f9:00 806308                             /opt/r/R-3.4.1/lib64/R/bin/exec/R

015a2000-0b362000 rw-p 00000000 00:00 0                                  [heap]

.

.

.

.

7f4b2aa87000-7f4b2aa89000 r--s 00008000 f9:01 1181509                    /opt/mana/nia_2.3/files/app/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-client-jobclient-2.7.1.jar

 

 

7f4b2ab7d000-7f4b2ab82000 r--s 0002c000 f9:01 1180872    Aborted

"

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

Java file:

"

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.util.Properties;

 

 

public class write_monthly {

 

public static void main(String args[]) throws Exception {

        String DAS= args[0];

        String DataSource= args[1];

        String df=args[2];

        String[] arr=null;

        write_monthly o1= new write_monthly();

        o1.name(DAS, DataSource, arr);

        

}

 

public String name(String DAS, String DataSource,String arr1[]) throws Exception {

         String url = "jdbc:pioledb://"+DAS+"/Data Source="+DataSource+";";

Class.forName("com.osisoft.jdbc.Driver").newInstance();

         String[] arr2= arr1;

        

        

   try{

        Connection con = DriverManager.getConnection(url, createPropertiesList());

       

        PreparedStatement stmt1=null;

  for(int i=0;i<arr2.length;i=i+9){

  String q1="INSERT piarchive..picomp2 (tag,value,time) VALUES ('"+"TMMF.Assembly.Forecasted Power Active Monthly',"+arr2[i+1]+",'"+arr2[i]+" 00:00:00')";

  System.out.println(q1);

  stmt1 = con.prepareStatement(q1);

  stmt1.executeQuery();

 

String q2="INSERT piarchive..picomp2 (tag,value,time) VALUES ('"+"TMMF.Plastic.Forecasted Power Active Monthly',"+arr2[i+2]+",'"+arr2[i]+" 00:00:00')";

  PreparedStatement stmt2 = con.prepareStatement(q2);

  stmt2.executeQuery();

 

String q3="INSERT piarchive..picomp2 (tag,value,time) VALUES ('"+"TMMF.Press.Forecasted Power Active Monthly',"+arr2[i+3]+",'"+arr2[i]+" 00:00:00')";

  PreparedStatement stmt3 = con.prepareStatement(q3);

  stmt3.executeQuery();

 

String q4="INSERT piarchive..picomp2 (tag,value,time) VALUES ('"+"TMMF.Weld.Forecasted Power Active Monthly',"+arr2[i+4]+",'"+arr2[i]+" 00:00:00')";

  PreparedStatement stmt4 = con.prepareStatement(q4);

  stmt4.executeQuery();

 

String q5="INSERT piarchive..picomp2 (tag,value,time) VALUES ('"+"TMMF.Office.Forecasted Power Active Monthly',"+arr2[i+5]+",'"+arr2[i]+" 00:00:00')";

  PreparedStatement stmt5 = con.prepareStatement(q5);

  stmt5.executeQuery();

 

String q6="INSERT piarchive..picomp2 (tag,value,time) VALUES ('"+"TMMF.Paint.Forecasted Power Active Monthly',"+arr2[i+6]+",'"+arr2[i]+" 00:00:00')";

  PreparedStatement stmt6 = con.prepareStatement(q6);

  stmt6.executeQuery();

 

String q7="INSERT piarchive..picomp2 (tag,value,time) VALUES ('"+"TMMF.Facilities.Forecasted Power Active Monthly',"+arr2[i+7]+",'"+arr2[i]+" 00:00:00')";

  PreparedStatement stmt7 = con.prepareStatement(q7);

  stmt7.executeQuery();

 

String q8="INSERT piarchive..picomp2 (tag,value,time) VALUES ('"+"TMMF.Logistics.Forecasted Power Active Monthly',"+arr2[i+8]+",'"+arr2[i]+" 00:00:00')";

  PreparedStatement stmt8 = con.prepareStatement(q8);

  stmt8.executeQuery();

 

 

}

 

System.out.println("success");

  con.commit();      

              con.close();

   }catch (Exception e) {

 

       e.printStackTrace();

       System.out.println("could not write forecasted data to osi pi");

 

        }

 

 

return("SUCCESS");

 

               }

private Properties createPropertiesList() {

Properties plist = new Properties();

plist.put("ProtocolOrder", "Https/Soap:5461,NetTcp:5462");

plist.put("LogConsole", "False");

plist.put("user", "xxxxx");

plist.put("password", "xxxxx");

plist.put("TrustedConnection","False");

plist.put("LogLevel", "5");

plist.put("DCA", "SAVE");

 

                return plist;

}

 

}

"

 

The script is successfully running if I remove the Insertion and connection part and simply iterate in the loop.

Can you please help in resolving this.

 

Thanks,

Ujjwal

Outcomes