Page 1 of 1

Beanshell to connect to Base table

Posted: Thu May 21, 2020 4:12 pm
by ztminhas
Hello,

I am trying to make a Beanshell macro in Base to connect to a table called schools. Here is my sample code:

Code: Select all

oDoc = UnoRuntime.queryInterface(XModel.class,XSCRIPTCONTEXT.getInvocationContext());
if ( oDoc == null )
  oDoc = XSCRIPTCONTEXT.getDocument();
oConn = oDoc.getCurrentController().connect("","");
oStmt = oConn.createStatement();
oStmt.executeUpdate( "update ""schools"" set ""name""='Name of School'  where ""ID""=1012" );
// BeanShell OpenOffice.org scripts should alsysways return 0
return 0;
I don't see any error, but it does not update. Can you please let me know what I am doing wrong?

Re: Beanshell to connect to Base table

Posted: Thu May 21, 2020 11:38 pm
by Villeroy
executeUpdate() returns the count of affected rows.
Try menu:View>"Refresh Tables". Base has no "notion" of SQL commands executed outside the GUI.

Re: Beanshell to connect to Base table

Posted: Fri May 22, 2020 6:16 am
by robleyd
Cross posted to AskLibreOffice