call path/spl(…)

Read(4918) Label: jdbc, search for a program file,

Description:

Search for a program file locally via esProc JDBC and execute it. If the file can’t be found, then search the server.

Syntax:

call path/spl(…)

Note:

The function calls a script file to execute it while passing in parameters …. It first searches the local cellset files with absolute or relative search paths for the desired one. If the file can’t be found locally, then search the server (configure the server list in the raqsoftConfig.xml file). Once the computation is completed, the function returns a sequence composed of members of the result set; if there are multiple result sets, then return a sequence composed of these result sets.

 

This is similar to calling a stored procedure in the normal database driver. During execution, use con.prepareCall() to call a statement in which the parameters can be written directly or set with st.setObject(). Once the statement is generated, use st.execute() to execute it and return the result set.

 

When calling the function, values arg1,... will be assigned to the script file’s parameters in turn, rather than according to the parameter names in its parameter list.

Parameter:

path

The relative search path or absolute search path of a file. The default setting is the relative search path when this parameter isn’t specified

spl

A script file .splx/.spl/.dfx, whose extension is determined according to the order of .splx/.spl/.dfx

Parameter. Use comma to separate the multiple parameters. The parameter names are irrelevant to the acceptance of the values, which, instead, will be assigned to the parameters in order

Example:

Below are the contents of the cellset file test.dfx, in which StuId and Class are the cellset parameters.

 

A

1

=connect("demo")

2

=A1.query("select * from SCORES where STUDENTID=? and CLASS=?",StuId,Class)

3

=A2.sum(SCORE)

4

>A1.close()

5

return A3

 

 

 

 

 

 

 

 

Test code is as follows:

public void testDataServer() {

    Connection con = null;

    java.sql.PreparedStatement st;

    try{

      Class.forName("com.esproc.jdbc.InternalDriver");

      con= DriverManager.getConnection("jdbc:esproc:local://");

      // Call the stored procedure in which test is the name of the dfx file

      st =con.prepareCall("call test(?,?)");

      // Set the first parameter

      st.setObject(1,"4");

// Set the second parameter

      st.setObject(2,"Class one");

      // Execute stored procedure

      st.execute();

      // Get result set

      ResultSet set = st.getResultSet();

      // Print results

      printRs(set); 

      // The following statement gets same result as the above-mentioned calling method has

      st =con.prepareCall("call test(4,\"Class one\")");

      st.execute();

      set = st.getResultSet();

      printRs(set);

    }

    catch(Exception e){

      System.out.println(e);

    }

    finally{

      // Close the connection

      if (con!=null) {

        try {

          con.close();

        }

        catch(Exception e) {

          System.out.println(e);

        }

      }

    }

  }