Arne Vajhøj
2026-04-13 15:07:48 UTC
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
(Java, Groovy, Kotlin, Scala etc.). Because Java developers for
decades has preferred Type 4 JDBC drivers (pure Java) over Type 2
JDBC drivers (Java wrapper around native client), then they can
usually just copy a Type 4 JDBC driver jar over from Windows/Linux
and they are good to go.
Everybody know that you can do:
Java code--(JNI)-->C/C++ code
But it is actually also possible to do:
C/C++ code--(JNI)-->Java code
So in theory a C/C++ application could use JNI to load a JVM and use
a Type 4 JDBC driver.
There is only one problem. JNI is a low level, pretty old and rather
cumbersome API to use. It would not be trivial to use JDBC via JNI.
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).
This code runs:
#include <iostream>
#include <string>
using namespace std;
#include "jdbc.h"
using namespace javaforcpp;
using namespace javaforcpp::java::sql;
#include "util.cpp"
int main()
{
try
{
jstring constr = newString("jdbc:mysql://arnepc5/Test");
jstring usr = newString("arne");
jstring pwd = newString("hemmeligt");
Connection con = DriverManager::getConnection(constr, usr, pwd);
jfree(constr);
jfree(usr);
jfree(pwd);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT f1,f2 FROM t1");
while(rs.next())
{
long int f1 = rs.getInt(1);
jstring f2 = rs.getString(2);
cout << f1 << " " << jstring2string(f2) << endl;
}
rs.close();
stmt.close();
con.close();
}
catch(jthrowable& ex)
{
PrintJThrowable("Exception in Java:\n", ex);
}
return 0;
}
(it should look very familiar to anyoine having used Java
and JDBC)
It is still using JNI under the hood. And there are a few things
that reveal it - there are references to jint, jstring,
jthrowable etc..
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.
Arne
database vendors do not see VMS as an important platform.
The only ones not having the problem are those using JVM languages
(Java, Groovy, Kotlin, Scala etc.). Because Java developers for
decades has preferred Type 4 JDBC drivers (pure Java) over Type 2
JDBC drivers (Java wrapper around native client), then they can
usually just copy a Type 4 JDBC driver jar over from Windows/Linux
and they are good to go.
Everybody know that you can do:
Java code--(JNI)-->C/C++ code
But it is actually also possible to do:
C/C++ code--(JNI)-->Java code
So in theory a C/C++ application could use JNI to load a JVM and use
a Type 4 JDBC driver.
There is only one problem. JNI is a low level, pretty old and rather
cumbersome API to use. It would not be trivial to use JDBC via JNI.
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).
This code runs:
#include <iostream>
#include <string>
using namespace std;
#include "jdbc.h"
using namespace javaforcpp;
using namespace javaforcpp::java::sql;
#include "util.cpp"
int main()
{
try
{
jstring constr = newString("jdbc:mysql://arnepc5/Test");
jstring usr = newString("arne");
jstring pwd = newString("hemmeligt");
Connection con = DriverManager::getConnection(constr, usr, pwd);
jfree(constr);
jfree(usr);
jfree(pwd);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT f1,f2 FROM t1");
while(rs.next())
{
long int f1 = rs.getInt(1);
jstring f2 = rs.getString(2);
cout << f1 << " " << jstring2string(f2) << endl;
}
rs.close();
stmt.close();
con.close();
}
catch(jthrowable& ex)
{
PrintJThrowable("Exception in Java:\n", ex);
}
return 0;
}
(it should look very familiar to anyoine having used Java
and JDBC)
It is still using JNI under the hood. And there are a few things
that reveal it - there are references to jint, jstring,
jthrowable etc..
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.
Arne