Liebe Studierende,
nachdem Sie in BP2 vereinzelt auch mit relationalen Datenbanken gearbeitet haben, könnte das folgende interessant für Sie sein, daher forwarde ich die Mail über den Listserver.
Mit freundlichem Gruß
Rony G. Flatscher
-------- Forwarded Message -------- Subject: Fwd: Little teaser on SQLite with BSF4ooRexx ... Date: Tue, 11 Aug 2020 17:52:06 +0200 From: Rony G. Flatscher Rony.Flatscher@wu.ac.at
Liebe Leute,
nachdem Ihr höchstwahrscheinlich mit RDBMS und Rexx Erfahrungen habt, anbei ein wahrscheinlich interessanter Beitrag. Der angesprochene JDBC-Treiber beinhaltet bereits die SQLite-Datenbank für Windows, Linux und MacOS, sodass Ihr das Beispiel nur mit dem JDBC-Treiber auf all diesen Plattformen laufen lassen könnt!
Voraussetzung ist, ooRexx 5.0 [1] und BSF4ooRexx [2] (externes Funktionspaket, das den Zugang zu Java transparent herstellt).
Liebe Grüße
---rony
[1] ooRexx 5.0: https://sourceforge.net/projects/oorexx/files/oorexx/5.0.0beta/ [2] BSF4ooRexx: https://sourceforge.net/projects/bsf4oorexx/files/beta/20190203/
-------- Forwarded Message -------- Subject: [RexxLA] Little teaser on SQLite with BSF4ooRexx ... Date: Tue, 11 Aug 2020 17:12:01 +0200 From: Rony G. Flatscher Rony.Flatscher@wu.ac.at Reply-To: RexxLA Members mailing list rexxla-members@rexxla.org To: RexxLA Members mailing list rexxla-members@rexxla.org
As the Rexx symposium is coming up, there may be many things that are of interest for Rexx programmers. In the context of experimenting with SQLite, a very popular database (e.g. even phones use it), I experimented with it a little bit in the context of BSF4ooRexx.
There is a JDBC-driver ("Java database connectivity") for SQLite, which interestingly also includes SQLite itself already! :)
Here the download location of the latest driver: https://repo1.maven.org/maven2/org/xerial/sqlite-jdbc/3.32.3.2/, download https://repo1.maven.org/maven2/org/xerial/sqlite-jdbc/3.32.3.2/sqlite-jdbc-3.32.3.2.jar.
With a plain BSF4ooRexx installation you can run this Rexx code which is exactly equivalent to the Java code "Sample.java" at https://github.com/xerial/sqlite-jdbc, if you make sure that the "sqlite-jdbc-3.32.3.2.jar" file is listed on the CLASSPATH environment variable, which Java uses to look for Java classes. E.g. on Windows issue
set CLASSPATH=%cd%\sqlite-jdbc-3.32.3.2.jar;%CLASSPATH%
Save the following Rexx program as "sample.rxj" and run it:
/* Rexx version of "Sample.java" at https://github.com/xerial/sqlite-jdbc as of 2020-08-11 Note: sqlite JDBC driver includes SQLite itself! Check at: https://repo1.maven.org/maven2/org/xerial/sqlite-jdbc/, developped with "sqlite-jdbc-3.32.3.2.jar" as of 2020-08-11 ---rgf, 2020-08-11 */ url="jdbc:sqlite:sample-rexx.db" signal on syntax name sqlException -- make sure we close the connection, if an exception occurs connection=bsf.import("java.sql.DriverManager")~getConnection(url)
statement =connection~createStatement statement~setQueryTimeout(30)
statement~executeUpdate("drop table if exists person") statement~executeUpdate("create table person (id integer, name string)") statement~executeUpdate("insert into person values(1, 'leo-rexx')") statement~executeUpdate("insert into person values(2, 'yui-rexx')")
rs=statement~executeQuery("select * from person") do while rs~next say "name =" rs~getString("name") say "id =" rs~getInt("id") -- could use rs~getString("id") instead end sqlException: if condition()<>"" then -- did we arrive here because of a Java exception? do say "Rexx condition occurred:" condition("Description") jexc=condition("Additional")~at(2) -- get Java Exception object do counter i while jexc<>.nil -- loop over Java exception chain say "---" say "cause #" i": jexc~toString:" jexc~toString jexc=jexc~getCause -- get cause if any left end end signal on any name done -- if exception closing connection, jump to label done connection~close -- close connection, if still open done:
::requires "BSF.CLS"
Its output will be:
F:\download\sql\sqlite\test>rexx sample.rxj name = leo-rexx id = 1 name = yui-rexx id = 2
Have fun! :)
---rony