NetSuite Data Provider - Online Help
NetSuite Data Provider
Questions / Feedback?

Calling Stored Procedures

Use the CallableStatement object to call stored procedures. First, establish a connection as described in Querying the Data. Then, create a CallableStatement object, set the parameters, and execute the command.

Class.forName("rssbus.jdbc.netsuite.NetSuiteDriver");
String connectionString = "jdbc:netsuite:Account Id=XABC123456;Password=password;User=user;Role Id=3;Version=2013_1;Location=C:\\myfolder\\;Offline=false;";
Connection conn = DriverManager.getConnection(connectionString);
CallableStatement cstmt = conn.prepareCall("GetRoles");
cstmt.setString("Account_Name", "Checking");
boolean ret = cstmt.execute();   
if (!ret){
  int count=cstmt.getUpdateCount();
  if (count!=-1)
  {
    System.out.println(count+" rows are affected");
  }
}
else{
  ResultSet rs=cstmt.getResultSet();
  while(rs.next()){
    for(int i=1;i<=rs.getMetaData().getColumnCount();i++)
    {
      System.out.println(rs.getMetaData().getColumnName(i) +"="+rs.getString(i));
    }
  }
}

Alternatively, you can call a stored procedure by instantiating a Statement object and setting the parameters in the command text. The support for stored procedure statements follows the standard form shown below:


EXECUTE my_proc @first = 1, @second = 2, @third = 3;

EXEC my_proc @first = 1, @second = 2, @third = 3;
The example below prints all entries for the netsuite object and sets the values of the parameters in the text of the command:
String connectionString = "jdbc:netsuite:Account Id=XABC123456;Password=password;User=user;Role Id=3;Version=2013_1;Location=C:\\myfolder\\;Offline=false;";
Connection conn = DriverManager.getConnection(connectionString);
Statement stmt = conn.createStatement();
boolean ret = stmt.execute("EXEC GetRoles Account_Name = Checking");
       
  if (!ret){
    int count=stmt.getUpdateCount();
    if (count!=-1)
    {
      System.out.println(count+" rows are affected");
    }
  }
  else{
    ResultSet rs=stmt.getResultSet();
    while(rs.next()){
      for(int i=1;i<=rs.getMetaData().getColumnCount();i++)
      {
        System.out.println(rs.getMetaData().getColumnName(i) +"="+rs.getString(i));
      }
    }
  }

 
 
Copyright (c) 2015 RSSBus, Inc. - All rights reserved.
Build 1.0.5577.0