[MonetDB-users] Calling a stored procedure from java

Hi, Please, I would like to know the correct sintaxis for calling a stored procedures in MonetDB from a Java application. I was using some code that works fine in MySQL but this doesn't work in MonetDB. The code inside a method is: ------------------------------------------------------------------- Connection con = null; ResultSet rs = null; CallableStatement cs = null; cs = con.prepareCall("{call hts.spInsertFile(?)}"); File fl = new File("/home//Test/example.pdf"); imgfile = new FileInputStream(fl); cs.setBinaryStream(1,imgfile); rs = cs.executeQuery(); ------------------------------------------------------------------- When I execute the stored procedure from Netbeans IDE the stored procedure works fine. I've made a trace in the application and the statement: con.prepareCall("{call hts.spInsertFile(?)}"); returns null and finally throws an exception: Exception in thread "main" java.lang.NullPointerException at testmonetdb.DBase.set_file(DBase.java:86) at testmonetdb.MonetDBTest.main(MonetDBTest.java:34) The MonetDB version I'm using is: MonetDB 5 server v11.3.7 "Apr2011-SP2" (64-bit, 64-bit oids) Copyright (c) 1993-July 2008 CWI Copyright (c) August 2008-2011 MonetDB B.V., all rights reserved Visit http://monetdb.cwi.nl/ for further information Found 3.9GiB available memory, 4 available cpu cores Libraries: libpcre: 8.12 2011-01-15 (compiled with 8.10) openssl: OpenSSL 1.0.0d 8 Feb 2011 (compiled with OpenSSL 1.0.0d-fips 8 Feb 2011) libxml2: 2.7.7 (compiled with 2.7.7) Compiled by: mockbuild@ (x86_64-unknown-linux-gnu) Compilation: gcc -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -O6 -fomit-frame-pointer -finline-functions -falign-loops=4 -falign-jumps=4 -falign-functions=4 -fexpensive-optimizations -funroll-loops -frerun-cse-after-loop -frerun-loop-opt -ftree-vectorize Linking : /usr/bin/ld -m elf_x86_64 I'm also using Netbeans IDE 7.1 with the jdbcclient.jar (http://dev.monetdb.org/downloads/Java/Oct2010-SP1/) Thanks in advance for your help, Enrique. -- View this message in context: http://old.nabble.com/Calling-a-stored-procedure-from-java-tp32431606p324316... Sent from the monetdb-users mailing list archive at Nabble.com.

Hi Enrique, On 09-09-2011 06:44:05 -0700, elarios wrote:
Please, I would like to know the correct sintaxis for calling a stored procedures in MonetDB from a Java application. I was using some code that works fine in MySQL but this doesn't work in MonetDB. The code inside a method is:
------------------------------------------------------------------- Connection con = null; ResultSet rs = null; CallableStatement cs = null;
cs = con.prepareCall("{call hts.spInsertFile(?)}");
This looks like JDBC escape syntax. We don't support this (yet) for performance reasons. We don't support CallableStatements either.
File fl = new File("/home//Test/example.pdf"); imgfile = new FileInputStream(fl);
cs.setBinaryStream(1,imgfile);
Datastreams are currently not supported by the database backend. These things have to be serialised, and written as block.
rs = cs.executeQuery();
In general we disadvice people to insert binary blobs in the database. If you really want to insert binary files in the database, make sure you use a blob, and that you use the PreparedStatement's setBytes() method.
participants (2)
-
elarios
-
Fabian Groffen