Beanshell to connect to Base table

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Posts: 1
Joined: Thu May 21, 2020 3:59 pm

Beanshell to connect to Base table

Post by ztminhas »


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 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?
Apache OpenOffice 4.1.7
Linux Mint 18.3
User avatar
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Beanshell to connect to Base table

Post 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.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Posts: 5082
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: Beanshell to connect to Base table

Post by robleyd »

Cross posted to AskLibreOffice
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice; SlackBuild for 24.2.2 by Eric Hameleers
Post Reply