Is it possible to call a Postgres stored function (as if it were a
procedure), using a PreparedStatement which will receive no return value,
instead of having to use a CallableStatement and ignore the return result?
The reason...
Our java middleware was written against Oracle (where we use stored
procedures extensively) and is now being ported to Postgres. I would
prefer not to have to rewrite all the java code replacing stored
PreparedStatement calls by CallableStatement calls.
We might have to move back to Oracle one day... Just kidding! ;)
Is there any way around the java code rewrite?
Thanks.
John Sidney-Woollett
Error message:
==============
org.postgresql.util.PSQLException: ERROR: syntax error at or near "{"
at
org.postgresql.util.PSQLException.parseServerError (PSQLException.java:139)
at org.postgresql.core.QueryExecutor.executeV3(QueryE xecutor.java:154) at
org.postgresql.core.QueryExecutor.execute(QueryExe cutor.java:101) at
org.postgresql.core.QueryExecutor.execute(QueryExe cutor.java:43) at
org.postgresql.jdbc1.AbstractJdbc1Statement.execut e(AbstractJdbc1Statement.java:515)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.execut e(AbstractJdbc2Statement.java:50)
at
org.apache.commons.dbcp.DelegatingPreparedStatemen t.execute(DelegatingPreparedStatement.java:230)
at
com.wardbrook.webdav.store.JDBCDavStore.updateDisk Usage(JDBCDavStore.java:1842)
at
com.wardbrook.webdav.store.JDBCDavStore.putResourc e(JDBCDavStore.java:449)
at
com.wardbrook.webdav.servlet.WebdavServlet.doPut(W ebdavServlet.java:674)
at
com.wardbrook.webdav.servlet.WebdavServlet.service (WebdavServlet.java:243)
Code as it now stands:
======================
//now delete the resource entry from the database
String sql = "{call UpdateDiskUsed(?,?)}";
Connection conn = null;
PreparedStatement ps = null;
try
{
//get the connection
conn = mDS.getConnection();
//create the statement
ps = conn.prepareStatement(sql.toString());
//set up the parameters
ps.setInt(1, resourceID);
ps.setInt(2, newContentLength);
//execute the procedure
ps.execute();
...
Code rewritten to work: (with Postgres)
=======================
//now delete the resource entry from the database
String sql = "{? = call UpdateDiskUsed(?,?)}";
Connection conn = null;
CallableStatement cs = null;
try
{
//get the connection
conn = mDS.getConnection();
//create the statement
cs = conn.prepareStatement(sql.toString());
//register the out parameter
cs.registerOutParameter(1, java.sql.Types.INTEGER);
//set up the parameters
cs.setInt(2, resourceID);
cs.setInt(3, newContentLength);
//execute the function
cs.execute();
//and ignore the function result!
...
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings 1 6154
John,
You should re-post this to the jdbc list.
Dave
On Wed, 2003-12-10 at 06:48, John Sidney-Woollett wrote: Is it possible to call a Postgres stored function (as if it were a procedure), using a PreparedStatement which will receive no return value, instead of having to use a CallableStatement and ignore the return result?
The reason...
Our java middleware was written against Oracle (where we use stored procedures extensively) and is now being ported to Postgres. I would prefer not to have to rewrite all the java code replacing stored PreparedStatement calls by CallableStatement calls.
We might have to move back to Oracle one day... Just kidding! ;)
Is there any way around the java code rewrite?
Thanks.
John Sidney-Woollett
Error message: ==============
org.postgresql.util.PSQLException: ERROR: syntax error at or near "{"
at org.postgresql.util.PSQLException.parseServerError (PSQLException.java:139) at org.postgresql.core.QueryExecutor.executeV3(QueryE xecutor.java:154) at org.postgresql.core.QueryExecutor.execute(QueryExe cutor.java:101) at org.postgresql.core.QueryExecutor.execute(QueryExe cutor.java:43) at org.postgresql.jdbc1.AbstractJdbc1Statement.execut e(AbstractJdbc1Statement.java:515) at org.postgresql.jdbc2.AbstractJdbc2Statement.execut e(AbstractJdbc2Statement.java:50) at org.apache.commons.dbcp.DelegatingPreparedStatemen t.execute(DelegatingPreparedStatement.java:230) at com.wardbrook.webdav.store.JDBCDavStore.updateDisk Usage(JDBCDavStore.java:1842) at com.wardbrook.webdav.store.JDBCDavStore.putResourc e(JDBCDavStore.java:449) at com.wardbrook.webdav.servlet.WebdavServlet.doPut(W ebdavServlet.java:674) at com.wardbrook.webdav.servlet.WebdavServlet.service (WebdavServlet.java:243)
Code as it now stands: ======================
//now delete the resource entry from the database String sql = "{call UpdateDiskUsed(?,?)}";
Connection conn = null; PreparedStatement ps = null;
try { //get the connection conn = mDS.getConnection();
//create the statement ps = conn.prepareStatement(sql.toString());
//set up the parameters ps.setInt(1, resourceID); ps.setInt(2, newContentLength);
//execute the procedure ps.execute(); ...
Code rewritten to work: (with Postgres) =======================
//now delete the resource entry from the database String sql = "{? = call UpdateDiskUsed(?,?)}";
Connection conn = null; CallableStatement cs = null;
try { //get the connection conn = mDS.getConnection();
//create the statement cs = conn.prepareStatement(sql.toString());
//register the out parameter cs.registerOutParameter(1, java.sql.Types.INTEGER);
//set up the parameters cs.setInt(2, resourceID); cs.setInt(3, newContentLength);
//execute the function cs.execute();
//and ignore the function result!
...
---------------------------(end of broadcast)--------------------------- TIP 7: don't forget to increase your free space map settings
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Maxim |
last post by:
Hi all!
My problem is very, very silly and stupid, I know, don't blame me for
that please...
When I call my query from SQL*Plus, I get the correct result:
SELECT check_passwd('user',...
|
by: Kent Lewandowski |
last post by:
hi all,
Recently I wrote some stored procedures using java jdbc code
(admittedly my first stab) and then tried to implement the same within
java packages (for code reuse). I encountered...
|
by: deegs_ca |
last post by:
Here is my jdbc info
url = jdbc:db2://LXPP04913:60000/TEST
driver = COM.ibm.db2.jdbc.net.DB2Driver
For some reason as I'm importing data via a jdbc client Db2 gets
through a few rows and then...
|
by: Praveen |
last post by:
Hi,
I have installed WebSphere Portal on AIX and connected to DB2 on a
remote machine, Getting the followin errors when trying to get the
values from database thru applications installed on...
|
by: Jim Steinberger |
last post by:
Hey all - my inaugural post,
I have a Java web application on Tomcat 5 using pg73jdbc3.jar to connect to
PostgreSQL 7.3.4 running on the same server (Red Hat Linux ).
I have a Perl...
|
by: veffen |
last post by:
Hello all,
I'm trying to call the snapshot table function SNAP_GET_TBSP via a jdbc
connection using the following query:
SELECT * FROM TABLE(SNAP_GET_TBSP(CAST(NULL AS VARCHAR(1), -1)) AS T
...
|
by: Kenevel |
last post by:
Hi there,
Is it possible to use inline SQL PL over JDBC? If so, which statement
type is required and what syntax does the inline SQL PL take? A
CallableStatement, for example, need to be...
|
by: %NAME% |
last post by:
(Thanks to Bernd, Ian, Phil last time for their detailed answers last
time) Now I try to call JDBC driver
without giving the username and password as they suggested. I am using
DB2 jdbc on SunOS...
|
by: robtyketto |
last post by:
Greetings,
I'm a newbie to Java and I cant quite get my head around why it seems most integers appears to be formatted as strings and then later have to be parsed.
The code below, passes in the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |