473,624 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JDBC function call: PS vs CS

Is it possible to call a Postgres stored function (as if it were a
procedure), using a PreparedStateme nt which will receive no return value,
instead of having to use a CallableStateme nt 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
PreparedStateme nt calls by CallableStateme nt 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.PSQLExcept ion: ERROR: syntax error at or near "{"

at
org.postgresql. util.PSQLExcept ion.parseServer Error(PSQLExcep tion.java:139)
at org.postgresql. core.QueryExecu tor.executeV3(Q ueryExecutor.ja va:154) at
org.postgresql. core.QueryExecu tor.execute(Que ryExecutor.java :101) at
org.postgresql. core.QueryExecu tor.execute(Que ryExecutor.java :43) at
org.postgresql. jdbc1.AbstractJ dbc1Statement.e xecute(Abstract Jdbc1Statement. java:515)
at
org.postgresql. jdbc2.AbstractJ dbc2Statement.e xecute(Abstract Jdbc2Statement. java:50)
at
org.apache.comm ons.dbcp.Delega tingPreparedSta tement.execute( DelegatingPrepa redStatement.ja va:230)
at
com.wardbrook.w ebdav.store.JDB CDavStore.updat eDiskUsage(JDBC DavStore.java:1 842)
at
com.wardbrook.w ebdav.store.JDB CDavStore.putRe source(JDBCDavS tore.java:449)
at
com.wardbrook.w ebdav.servlet.W ebdavServlet.do Put(WebdavServl et.java:674)
at
com.wardbrook.w ebdav.servlet.W ebdavServlet.se rvice(WebdavSer vlet.java:243)
Code as it now stands:
=============== =======

//now delete the resource entry from the database
String sql = "{call UpdateDiskUsed( ?,?)}";

Connection conn = null;
PreparedStateme nt ps = null;

try
{
//get the connection
conn = mDS.getConnecti on();

//create the statement
ps = conn.prepareSta tement(sql.toSt ring());

//set up the parameters
ps.setInt(1, resourceID);
ps.setInt(2, newContentLengt h);

//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;
CallableStateme nt cs = null;

try
{
//get the connection
conn = mDS.getConnecti on();

//create the statement
cs = conn.prepareSta tement(sql.toSt ring());

//register the out parameter
cs.registerOutP arameter(1, java.sql.Types. INTEGER);

//set up the parameters
cs.setInt(2, resourceID);
cs.setInt(3, newContentLengt h);

//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

Nov 12 '05 #1
1 6184
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 PreparedStateme nt which will receive no return value,
instead of having to use a CallableStateme nt 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
PreparedStateme nt calls by CallableStateme nt 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.PSQLExcept ion: ERROR: syntax error at or near "{"

at
org.postgresql. util.PSQLExcept ion.parseServer Error(PSQLExcep tion.java:139)
at org.postgresql. core.QueryExecu tor.executeV3(Q ueryExecutor.ja va:154) at
org.postgresql. core.QueryExecu tor.execute(Que ryExecutor.java :101) at
org.postgresql. core.QueryExecu tor.execute(Que ryExecutor.java :43) at
org.postgresql. jdbc1.AbstractJ dbc1Statement.e xecute(Abstract Jdbc1Statement. java:515)
at
org.postgresql. jdbc2.AbstractJ dbc2Statement.e xecute(Abstract Jdbc2Statement. java:50)
at
org.apache.comm ons.dbcp.Delega tingPreparedSta tement.execute( DelegatingPrepa redStatement.ja va:230)
at
com.wardbrook.w ebdav.store.JDB CDavStore.updat eDiskUsage(JDBC DavStore.java:1 842)
at
com.wardbrook.w ebdav.store.JDB CDavStore.putRe source(JDBCDavS tore.java:449)
at
com.wardbrook.w ebdav.servlet.W ebdavServlet.do Put(WebdavServl et.java:674)
at
com.wardbrook.w ebdav.servlet.W ebdavServlet.se rvice(WebdavSer vlet.java:243)
Code as it now stands:
=============== =======

//now delete the resource entry from the database
String sql = "{call UpdateDiskUsed( ?,?)}";

Connection conn = null;
PreparedStateme nt ps = null;

try
{
//get the connection
conn = mDS.getConnecti on();

//create the statement
ps = conn.prepareSta tement(sql.toSt ring());

//set up the parameters
ps.setInt(1, resourceID);
ps.setInt(2, newContentLengt h);

//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;
CallableStateme nt cs = null;

try
{
//get the connection
conn = mDS.getConnecti on();

//create the statement
cs = conn.prepareSta tement(sql.toSt ring());

//register the out parameter
cs.registerOutP arameter(1, java.sql.Types. INTEGER);

//set up the parameters
cs.setInt(2, resourceID);
cs.setInt(3, newContentLengt h);

//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

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3940
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', 'password') FROM dual; CHECK_PASSWD('USER','PASSWORD')
2
9217
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 problems doing this. I wanted to implemented a generic "Helper" class like this: /** * Helper
3
4453
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 crashes. Subsequent connections receive the Caused by: COM.ibm.db2.jdbc.DB2Exception:
1
9011
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 Portal. Any Help Appreciated. Thanks in advance. Praveen Singh
6
1913
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 script that drops the database and rebuilds it with all of our
8
4550
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 In CLP this works properly, but when I execute it from java, I get the following SQL exception:
5
3514
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 enclosed within curly braces: eg: {CALL some_procedure()} Cheers
2
5956
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 5.8 with db2 version 7.2.0. When I am using the type2 network driver (COM.ibm.db2.jdbc.net.DB2Driver) with username and password, everything is fine. However, when I use the application driver: (COM.ibm.db2.jdbc.app.DB2Driver), and call...
4
1732
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 autonumber table field Id value named faqId which in the HTML code the Input type is "Int" <FORM NAME ="deletefaqs" ACTION="wk465682DeleteFAQbean.jsp" METHOD="POST"><PRE> Id: <INPUT TYPE="Int" NAME="faqId"> <BR><BR> <input type="submit" ...
0
8242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8177
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8681
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8629
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7170
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.