Beanshell to connect to Base table

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

Beanshell to connect to Base table

Post 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?
Apache OpenOffice 4.1.7
Linux Mint 18.3
User avatar
Villeroy
Volunteer
Posts: 31295
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
robleyd
Moderator
Posts: 5167
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
Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.5.2; SlackBuild for 24.2.5 by Eric Hameleers
---------------------
Roses are Red, Violets are Blue
Unexpected '{' on line 32
.
Post Reply