#include <iostream>
#include <string>
using namespace std;
#include "jdbc.h"
using namespace javaforcpp;
using namespace javaforcpp::java::sql;
#include "util.cpp"
int main()
{
-a-a-a-a try
-a-a-a-a {
-a-a-a-a-a-a-a-a jstring constr = newString("jdbc:mysql://arnepc5/Test"); -a-a-a-a-a-a-a-a jstring usr = newString("arne");
-a-a-a-a-a-a-a-a jstring pwd = newString("hemmeligt");
-a-a-a-a-a-a-a-a Connection con = DriverManager::getConnection(constr, usr, pwd);
-a-a-a-a-a-a-a-a jfree(constr);
-a-a-a-a-a-a-a-a jfree(usr);
-a-a-a-a-a-a-a-a jfree(pwd);
-a-a-a-a-a-a-a-a Statement stmt = con.createStatement();
-a-a-a-a-a-a-a-a ResultSet rs = stmt.executeQuery("SELECT f1,f2 FROM t1"); -a-a-a-a-a-a-a-a while(rs.next())
-a-a-a-a-a-a-a-a {
-a-a-a-a-a-a-a-a-a-a-a-a long int f1 = rs.getInt(1);
-a-a-a-a-a-a-a-a-a-a-a-a jstring f2 = rs.getString(2); -a-a-a-a-a-a-a-a-a-a-a-a cout << f1 << " " << jstring2string(f2) << endl; -a-a-a-a-a-a-a-a }
-a-a-a-a-a-a-a-a rs.close();
-a-a-a-a-a-a-a-a stmt.close();
-a-a-a-a-a-a-a-a con.close();
-a-a-a-a }
-a-a-a-a catch(jthrowable& ex)
-a-a-a-a {
-a-a-a-a-a-a-a-a PrintJThrowable("Exception in Java:\n", ex);
-a-a-a-a }
-a-a-a-a return 0;
}
On Mon, 2026-04-13 at 11:07 -0400, Arne Vajh|+j wrote:
-a-a-a-a-a-a-a-a jstring constr = newString("jdbc:mysql://arnepc5/Test"); >> -a-a-a-a-a-a-a-a jstring usr = newString("arne");
-a-a-a-a-a-a-a-a jstring pwd = newString("hemmeligt");
-a-a-a-a-a-a-a-a Connection con = DriverManager::getConnection(constr, usr, pwd);
-a-a-a-a catch(jthrowable& ex)
-a-a-a-a {
-a-a-a-a-a-a-a-a PrintJThrowable("Exception in Java:\n", ex);
-a-a-a-a }
Only jthrowable is caught; C++ exceptions from newString or other code
will bypass the handler.
Oops!
But overall the code is a thousand times nicer than normal JNI
code. No magic but java4cpp generated about 30000 lines of wrapper
C++ code. It helps.
If anyone want to try it:
https://www.vajhoej.dk/arne/vmsstuff/jdbc/
I have tested with:
* H2
* MySQL
* PostgreSQL
* Oracle DB
* IBM DB2
* MS SQLServer
That covers a lot of the most common RDBMS'es.
It works pretty well. Happy path and simple SQLException are all good.
But mess up with the JNI stuff and you will see some really bad
program crashes. You have been warned.
On 2026-04-13, Arne Vajh|+j <arne@vajhoej.dk> wrote:
I have tested with:
* H2
* MySQL
* PostgreSQL
* Oracle DB
* IBM DB2
* MS SQLServer
That covers a lot of the most common RDBMS'es.
It works pretty well. Happy path and simple SQLException are all good.
But mess up with the JNI stuff and you will see some really bad
program crashes. You have been warned.
Only if you are lucky. If you are unlucky, a faulty JNI program will not crash.
Fortunately, I rapidly learnt to keep it simple when writing JNI-based interfaces, so I am far less in need of luck than I otherwise would be. :-)
And for the more common case of native->Java, then JNI is
obsolete by now. Anyone being on Java 21+/25+ should use
Foreign Function instead of JNI. Much more high level
(and the glue code is on the Java side not the native side).
But recently I fell over an interesting open source project java4cpp (https://github.com/wshackle/java4cpp)) that automatically generates
C++ wrappers from Java classes (via reflection).
So I tried to generate C++ wrappers for JDBC. And it worked. And it
also worked on VMS (VMS x86-64 - I have not tried with the older
C++ compilers on Alpha/Itanium).
On 4/13/2026 11:07 AM, Arne Vajh|+j wrote:
But recently I fell over an interesting open source project java4cpp
(https://github.com/wshackle/java4cpp)) that automatically generates
C++ wrappers from Java classes (via reflection).
So I tried to generate C++ wrappers for JDBC. And it worked. And it
also worked on VMS (VMS x86-64 - I have not tried with the older
C++ compilers on Alpha/Itanium).
And C++ classes can be wrapped as C functions.
And C functions can be wrapped for Pascal.
I tried writing a few of those wrappers.
Database client libraries for VMS are often a problem, because
database vendors do not see VMS as an important platform.
The only ones not having the problem are those using JVM languages
But recently I fell over an interesting open source project java4cpp (https://github.com/wshackle/java4cpp)) that automatically generates
C++ wrappers from Java classes (via reflection).
So I tried to generate C++ wrappers for JDBC. And it worked. And it
also worked on VMS (VMS x86-64 - I have not tried with the older
C++ compilers on Alpha/Itanium).
On 4/14/2026 5:34 PM, Craig A. Berry wrote:
On 4/13/26 10:07 AM, Arne Vajh|+j wrote:
But recently I fell over an interesting open source project java4cpp
(https://github.com/wshackle/java4cpp)) that automatically generates
C++ wrappers from Java classes (via reflection).
So I tried to generate C++ wrappers for JDBC. And it worked. And it
also worked on VMS (VMS x86-64 - I have not tried with the older
C++ compilers on Alpha/Itanium).
It's a clever workaround and it looks like you had fun working up the
proof of concept,
Having fun is what drives this kind of effort.
-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a I'm not convinced it's a great general
solution.
I don't think it is bad from a technical perspective:
* it works
* it is not introducing an extra tier
* it is a very nice API that millions of developers already know
But do I think there will be any interest in using it? No!
I expect practically zero interest.
On 4/14/2026 5:34 PM, Craig A. Berry wrote:
On 4/13/26 10:07 AM, Arne Vajh|+j wrote:
Database client libraries for VMS are often a problem, because
database vendors do not see VMS as an important platform.
The only ones not having the problem are those using JVM languages
That's a little overstated. VSI has ported SQL Relay:
https://sqlrelay.sourceforge.net/index.html
which supports quite a few of the major DBMS players.
I know about SQLRelay.
https://www.vajhoej.dk/arne/articles/vmstd2.html
:-)
And SQLRelay is certainly a relevant solution to the problem. It
supports almost all major RDBMS.
But it is a different model.
It is not:
app->DB client lib----->DB
but:
app->SQLRelay client lib----->SQLRelay server->DB client lib----->DB
And the JDBC API is a bit nicer than the SQLRelay API if you ask
me. For various reasons including:
* same parameter placeholder for all databases
* database meta data
In all fairness then SQLRelay does have one big
advantage: it comes with an embedded SQL precompiler
for C and Cobol.
That is important for VMS, because a big part of
existing VMS database applications use embedded SQL
(because they were created at a time where embedded
SQL was "the way").
In practice that may count for a lot more than
some of the nice JDBC features like database
meta data and escape syntax.
Arne
On 4/15/2026 7:56 PM, Arne Vajh|+j wrote:
In all fairness then SQLRelay does have one big
advantage: it comes with an embedded SQL precompiler
for C and Cobol.
Any hint as to where one would find that?-a I looked at their
web pages and could find no mention of a Pre-Compiler or COBOL.
That is important for VMS, because a big part of
existing VMS database applications use embedded SQL
(because they were created at a time where embedded
SQL was "the way").
Also, no mention of VMS in the supported platforms.
On 4/16/2026 5:02 PM, bill wrote:
On 4/15/2026 7:56 PM, Arne Vajh|+j wrote:
In all fairness then SQLRelay does have one big
advantage: it comes with an embedded SQL precompiler
for C and Cobol.
Any hint as to where one would find that?-a I looked at their
web pages and could find no mention of a Pre-Compiler or COBOL.
That is important for VMS, because a big part of
existing VMS database applications use embedded SQL
(because they were created at a time where embedded
SQL was "the way").
Also, no mention of VMS in the supported platforms.
It is supported on VMS by VSI (to the extent they support
the open source software they port).
https://products.vmssoftware.com/libsqlrelay
The page is actually outdated. It says V1.9-3G, but
the actual SP has V2.0-0E for Itanium and x86-64.
After install you do:
$ presqlr :== $sqlr$root:[bin]presqlr.exe
and:
$ presqlr /lang=c /iname=pre.pc /oname=pre.c
$ presqlr /lang=cob /iname=pre.pco /oname=pre.cob
Note that like any other embedded SQL precompiler (except SQLJ),
then it is for a specific target - in this case SQLRelay.
On 4/16/2026 5:02 PM, bill wrote:
On 4/15/2026 7:56 PM, Arne Vajh|+j wrote:
In all fairness then SQLRelay does have one big
advantage: it comes with an embedded SQL precompiler
for C and Cobol.
Any hint as to where one would find that?-a I looked at their
web pages and could find no mention of a Pre-Compiler or COBOL.
That is important for VMS, because a big part of
existing VMS database applications use embedded SQL
(because they were created at a time where embedded
SQL was "the way").
Also, no mention of VMS in the supported platforms.
It is supported on VMS by VSI (to the extent they support
the open source software they port).
https://products.vmssoftware.com/libsqlrelay
The page is actually outdated. It says V1.9-3G, but
the actual SP has V2.0-0E for Itanium and x86-64.
After install you do:
$ presqlr :== $sqlr$root:[bin]presqlr.exe
and:
$ presqlr /lang=c /iname=pre.pc /oname=pre.c
$ presqlr /lang=cob /iname=pre.pco /oname=pre.cob
Note that like any other embedded SQL precompiler (except SQLJ),
then it is for a specific target - in this case SQLRelay.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 65 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 06:08:40 |
| Calls: | 862 |
| Files: | 1,311 |
| D/L today: |
921 files (14,318M bytes) |
| Messages: | 264,697 |