CREATE JAVACLASS

CREATE JAVACLASS — loads a Java class for use in stored procedures

Syntax

CREATE JAVACLASS [ IF NOT EXISTS ] classid FROM 'path/to/javaproc.jar';
CREATE JAVACLASS [ IF NOT EXISTS ] classid FROM ?;

Description

Upload to the NuoDB servers a JAR containing methods suitable for implementing Java stored procedures. When invoked inside NuoSQL, the command can use the first syntax and directly use the path (relative to the local file system) of the JAR archive. When invoked via any other client API (JDBC, ODBC, .NET, Python…​) the client code must prepare a statement using the second syntax and bind the parameter with a BLOB holding the bytes of the JAR archive.

Parameters

classid

The ID used to identify the JAR archive during the creation of a Java stored procedure. See Using Embedded Java Stored Procedures.

path | ?

The location or bytes of the JAR archive containing the javaclass.

Example

CREATE JAVACLASS firstprocid FROM 'test.jar';
PreparedStatement pstmt =
    connection.prepareStatement("CREATE JAVACLASS firstprocid FROM ?");
Blob jarData = connection.createBlob();
OutputStream blobStream = jarData.setBinaryStream(1);
FileInputStream jarInputStream = new FileInputStream(jarFile);
int read = 0;
while((read = jarInputStream.read(buffer)) > 0) {
    blobStream.write(buffer, 0, read);
}
pstmt.setBlob(1, jarData);
pstmt.execute();