Running a JasperReport with JasperStarter doesn't create an output file - jasper-reports

I have the following set-up:
A LibreOffice Base mybase.odb connected to an HSQLDB Split-DB named mydb
A form within with a button to open a report
A macro behind this button that basically performs:
shell(convertToUrl(Tools.Strings.DirectoryNameOutOfPath( _
ThisComponent.Parent.getURL(), "/") & "myReport.cmd"), HIDE)
myReport.cmd contains:
:: From: http://hsqldb.org/doc/2.0/guide/listeners-chapt.html#lsc_listener_types
start /min java -cp %~dp0driver/hsqldb.jar org.hsqldb.server.Server
--database.0 file:mydb --dbname.0 mydb
timeout /t 3
:: From: http://jasperstarter.cenote.de/index.html
jasperstarter -v pr %~dp0myReport.jasper -r -o . -f pdf
-H [localhost|127.0.0.1] --db-port 9001 -n mydb -u myuser
[Line breaks inserted for easier reading here.]
The HSQLDB server starts succesfully:
...
[Server#1742700]: Startup sequence completed in 382 ms.
[Server#1742700]: 2016-05-09 23:05:49.129 HSQLDB server 2.3.2 is online on port 9001
...
The subsequent JasperStarter doesn't show any error but no PDF is created.
Following the HSQLDB server output Server#1742700 I also tried (with little hope):
jasperstarter ... -H 1742700 ... -n Server
to no avail.
The following in myReport.cmd works like a charm standalone:
jasperstarter pr %~dp0myReport.jasper -r -o . -f pdf -t generic
--jdbc-dir %~dp0driver --db-driver org.hsqldb.jdbcDriver
--db-url jdbc:hsqldb:file:%~dp0database/mydb;sql.syntax_mys=true;shutdown=true
-u myuser
[Line breaks inserted for easier reading here.]
But not, of course, if mybase.odb is open:
Unable to connect to database: Database lock acquisition failure: lockFile:
org.hsqldb.persist.LockFile#68306856[file =<path>\database\mydb.lck, exists=true,
locked=false, valid=false, ] method: checkHeartbeat read: 2016-05-09 21:25:13
heartbeat - read: -6188 ms.
BTW, why locked=false when the lock file exists?

According to fredt's answer I created a myapp.cmd containing:
start "My DB Server" /min java -cp %~dp0driver/hsqldb.jar org.hsqldb.server.Server
--database.0 file:%~dp0database/mydb --dbname.0 mydb
timeout /t 2
start /b /max %~dp0mybase.odb
myReport.cmd now contains just:
jasperstarter -v pr %~dp0myReport.jasper -r -o %~dp0 -f pdf
-H localhost --db-port 9001 -n mydb -u myuser
And I realized that:
jasperstarter ... -o .
doesn't work as expected. With '.' it took C:\Program Files (x86)\LibreOffice 5\program as output directory (comprehensible if invoked from within Base). Hence I changed it to the absolute %~dp0.

Only one Java process at a time can connect to a file: database. The message indicates the second process cannot acquire a lock because the lock file has been created by the other process and does exist.
You should change the setup so that HSQLDB Server is started before you start LibreOffice. LibreOffice then connects to the server database, and your macro no longer starts the server and just starts the report generator with the Server URL.

Related

Postgres Copy command with Log redirection

I am using Postgres Copy utility to load the data to Postgres table from CSV file. Currently using the below command
psql -h 127.0.0.1 -d target -U postgres -c "\copy TableName FROM 'E:\Dev\XXX_1_0.csv' delimiter '^'" -o E:/Dev/XXX.log
When there is an issue in the data, error information are not getting updated in the log file.
Whereas when there is no error, my log files is updated with loaded row count. fo example (COPY 25)
I tried to execute the above command from command prompt & below error is reported.
Let me know how to get the error information or redirect the errors to log files for the reference.
ERROR: value too long for type character varying(255)
CONTEXT: COPY TableName, line 2, column Name: "NickName..."
I don't know of a way to redirect the error output directly in psql. You can get your shell to do it for you.
This works to combine both stdout and stderr into one file named "log". It works both in bash and in Windows CMD:
psql -c "whatever" > log 2>&1

PSQL COPY can't find file

I am trying to execute this command:
PS C:\Program Files\PostgreSQL\9.4\bin> .\psql.exe -h front.linux-pgsql01.qa.local -p 5432 -d site -U qa -w -c "Delete from product_factor_lolek; COPY product_factor_lolek FROM E'C:\\OP_data\\SEARCH\\1.csv' delimiter '^' CSV;"
My file is located on this path: C:\OP_data\SEARCH\1.csv. But in fact, I've got an error:
ERROR: could not open file "C:\OP_data\SEARCH\1.csv" for reading: No such file or directory
I am using Windows server, PostgreSQL 9.4. What should I write for correct path?
P.S. I can't use \COPY
The COPY command will attempt to access your CSV file on Server (front.linux-pgsql01.qa.local), not in the client. So you must send your CSV to there and point the command to its path or use stdin as you mentioned:
psql.exe -h front.linux-pgsql01.qa.local -p 5432 -d site -U qa -w -c "Delete from product_factor_lolek; COPY product_factor_lolek FROM STDIN' delimiter '^' CSV;" < C:\OP_data\SEARCH\1.csv

Importing zipped CSV file into PostgreSQL

I have a big compressed csv file (25gb) and I want to import it into PostgreSQL 9.5 version. Is there any fast way to import zip or qzip file into postgres without extracting the file?
There is an old trick to use a named pipe (works on Unix, don't know about Windows)
create a named pipe: mkfifo /tmp/omyfifo
write the file contents to it: zcat mycsv.csv.z > /tmp/omyfifo &
[from psql] copy mytable(col1,...) from '/tmp/omyfifo'
[when finished] : rm /tmp/omyfifo
The zcat in the backgound will block until a reader (here: the COPY command) will start reading, and it will finish at EOF. (or if the reader closes the pipe)
You could even start multiple pipes+zcat pairs, which will be picked up by multiple COPY statements in your sql script.
This will work from pgadmin, but the fifo (+zcat process) should be present on the machine where the DBMS server runs.
BTW: a similar trick using netcat can be used to read a file from a remote machine (which of course should write the file to the network socket)
example how to do it with zcat and pipe:
-bash-4.2$ psql -p 5555 t -c "copy tp to '/tmp/tp.csv';"
COPY 1
-bash-4.2$ gzip /tmp/tp.csv
-bash-4.2$ zcat /tmp/tp.csv.gz | psql -p 5555 t -c "copy tp from stdin;"
COPY 1
-bash-4.2$ psql -p 5555 t -c "select count(*) from tp"
count
-------
2
(1 row)
also from 9.3 release you can:
psql -p 5555 t -c "copy tp from program 'zcat /tmp/tp.csv.gz';"
without pipe at all
If you have a ZIP (.zip) instead of a GZIP (.gz) archive, you can use unzip -p to pipe the zipped file.
psql -p 5555 -t -c "copy tp from program 'unzip -p /tmp/tp.csv.zip';"

pgAgent scheduled job failed on Windows

I am trying to set up the step with Batch file path on particular time in pgAgent via pgAdmin. But when I run that it is failing and in Step statistics I got this Output
C:\Windows\system32>C:\postgresql\run.bat
'psql' is not recognized as an internal or external command,
operable program or batch file.
Details:
Postgresql 9.3.5 on local system account (Current User)
pgAdmin 1.18.1
pgAgent via stack builder with Administrator account (Current User)
in run.bat I have only two statement
#echo off
psql -h localhost -p 5433 -U postgres -d test -a -f "test.sql"
I have psql in system path variable and able to access it in cmd. When I run that bat file manually it is executing without fail. But when I given the batch file path (C:\postgresql\run.bat) in pgAgent jobs it is giving that error in statistics.
Is there anything wrong in my configuration? Why it is always going to that C:\Windows\system32>?
Edit:
My run.bat file
#ECHO OFF
SET LBSDatabaseName=Test
SET dbHost=localhost
SET dbPort=5434
SET dbUser=postgres
SET logFile=DbInstall.log
SET sqlFolder="D:\SOURCECODE\archivescripts"
"C:\Program Files (x86)\PostgreSQL\9.3\bin\psql.exe" -h "%dbHost%" -p "%dbPort%" -d "%LBSDatabaseName%" -U "%dbUser%" -L "%logFile%" -q -f "%sqlFolder%\Archive.sql"
My Archive.sql
update "Archive".emp set "FirstName"='Srikanth Dyapa';
For example,
D:\pgAgent_jobs
is the path where psql located.
D:\pgAgent_jobs\scripts\test.sql
is the path in which my test.sql placed.
D:\pgAgent_jobs\scripts\psqlss.bat
is my bat file to execute test.sql
so my bat file will be like below
#echo off
cd /D D:\\pgAgent_jobs
psql -h localhost -p 5432 -U postgres -d db_name -a -f "D:\pgAgent_jobs\scripts\test.sql"
Note : my pg_hba.conf is configured with trust for all hosts that's why am not passing any password in the above psql command

Upstart / init script not working

I'm trying to create a service / script to automatically start and controll my nodejs server, but it doesnt seem to work at all.
First of all, I used this source as main reference http://kvz.io/blog/2009/12/15/run-nodejs-as-a-service-on-ubuntu-karmic/
After testing around, I minimzed the content of the actual file to avoid any kind of error, resulting in this (the bare minimum, but it doesnt work)
description "server"
author "blah"
start on started mountall
stop on shutdown
respawn
respawn limit 99 5
script
export HOME="/var/www"
exec nodejs /var/www/server/server.js >> /var/log/node.log 2>&1
end script
The file is saved in /etc/init/server.conf
when trying to start the script (as root, or normal user), I get:
root#iof304:/etc/init# start server
start: Job failed to start
Then, I tried to check my syntax with init-checkconf, resulting in:
$ init-checkconf /etc/init/server.conf
File /etc/init/server.conf: syntax ok
I tried different other things, like initctl reload-configuration with no result.
What can I do? How can I get this to work? It can't be that hard, right?
This is what our typical startup script looks like. As you can see we're running our node processes as user nodejs. We're also using the pre-start script to make sure all of the log file directories and .tmp directories are created with the right permissions.
#!upstart
description "grabagadget node.js server"
author "Jeffrey Van Alstine"
start on started mysql
stop on shutdown
respawn
script
export HOME="/home/nodejs"
exec start-stop-daemon --start --chuid nodejs --make-pidfile --pidfile /var/run/nodejs/grabagadget.pid --startas /usr/bin/node -- /var/nodejs/grabagadget/app.js --environment production >> /var/log/nodejs/grabagadget.log 2>&1
end script
pre-start script
mkdir -p /var/log/nodejs
chown nodejs:root /var/log/nodejs
mkdir -p /var/run/nodejs
mkdir -p /var/nodejs/grabagadget/.tmp
# Git likes to reset permissions on this file, but it really needs to be writable on server start
chown nodejs:root /var/nodejs/grabagadget/views/layout.ejs
chown -R nodejs:root /var/nodejs/grabagadget/.tmp
# Date format same as (new Date()).toISOString() for consistency
sudo -u nodejs echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >> /var/log/nodejs/grabagadget.log
end script
pre-stop script
rm /var/run/nodejs/grabagadget.pid
sudo -u nodejs echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >> /var/log/nodejs/grabgadget.log
end script
As of Ubuntu 15, upstart is no longer being used, see systemd.