pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Hannu Krosing <hannu@2ndQuadrant.com>
To: Dave Cramer <pg@fastcrypt.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: What do people use for connection pooling with PostgreSQL  JDBC
Date: Tue, 07 Apr 2009 17:02:53 +0300
Message-ID: <1239112973.7647.23.camel@huvostro> (raw)
In-Reply-To: <491f66a50904070639g6fe91d6dxa0f856e42e5cccce@mail.gmail.com>
References: <1236241901.12460.6.camel@huvostro>
	<491f66a50903050513r46ab0531h4892e973dec51f18@mail.gmail.com>
	<1239016398.8411.2.camel@huvostro>
	<491f66a50904060443o7e80fae8mfb6f403fb9a53467@mail.gmail.com>
	<1239093322.7647.9.camel@huvostro>
	<491f66a50904070324g19aee516vb5b1922b23450a27@mail.gmail.com>
	<1239110612.7647.15.camel@huvostro>
	<491f66a50904070639g6fe91d6dxa0f856e42e5cccce@mail.gmail.com>

On Tue, 2009-04-07 at 09:39 -0400, Dave Cramer wrote:
> 
> 
> On Tue, Apr 7, 2009 at 9:23 AM, Hannu Krosing <hannu@2ndquadrant.com>
> wrote:
>         
>         On Tue, 2009-04-07 at 06:24 -0400, Dave Cramer wrote:
>         >
>         >
>         > On Tue, Apr 7, 2009 at 4:35 AM, Hannu Krosing
>         <hannu@2ndquadrant.com>
>         > wrote:
>         >         On Mon, 2009-04-06 at 07:43 -0400, Dave Cramer
>         wrote:
>         >         > huh ? What makes you think it doesn't deal with
>         arrays ?
>         >
>         >
>         >         I have a sample function, whit takes an array
>         argument
>         >
>         >         CREATE OR REPLACE FUNCTION arraySum(
>         >                multiplier bigint,
>         >                valuelist bigint[],
>         >                OUT result int
>         >         ) AS
>         >         $$
>         >         BEGIN
>         >            result = 0;
>         >            FOR idx IN array_lower(valuelist,
>         >         1)..array_upper(valuelist, 1) LOOP
>         >                result = result + multiplier *
>         valuelist[idx];
>         >            END LOOP;
>         >            RETURN;
>         >         END;
>         >         $$ LANGUAGE plpgsql SECURITY DEFINER;
>         >
>         >
>         >         When I call this function directly via JDBC or using
>         proxool I
>         >         get a
>         >         result, when doing it via c3p0 or dbcp I get an
>         exception -
>         >
>         >           Long[] array = { 1L, 2L };
>         >           PreparedStatement ps = conn.prepareStatement(
>         >                "SELECT * FROM arraySum(?, ?)");
>         >           ps.setLong(1, 3L);
>         >           ps.setArray(2, conn.createArrayOf("bigint",
>         array));
>         >           ps.execute();
>         >
>         > OK, createArrayOf is a relatively new method. So .... you
>         have a few
>         > ways around this.
>         >
>         > 1) don't use it, create your own arrays.
>         > 2) fix the dbcp code
>         > 3) complain to dbcp people
>         
>         
>         It's both dbcp and c3po.
>         
>         I understand that dbcp and c3po work on some other databases
>         jdbc
>         drivers, so maybe I could also do
>         
>         4) fix jdbc code to provide required createArrayOf support
>         
>         no ?
> 
> Well, the newer drivers support createArray, so perhaps you need a
> newer driver ?

As I said, yhis works when I use JDBC directly, or proxool connection
proxy

> As well as showing us the exception. 

for dbcp -

java.lang.AbstractMethodError:
org.apache.tomcat.dbcp.dbcp.PoolingDataSource
$PoolGuardConnectionWrapper.createArrayOf(Ljava/lang/String;[Ljava/lang/Object;)Ljava/sql/Array;


for c3p0 -

java.lang.AbstractMethodError:
com.mchange.v2.c3p0.impl.NewProxyConnection.createArrayOf(Ljava/lang/String;[Ljava/lang/Object;)Ljava/sql/Array;

Servlet code to test direct, proxool, c3po and dbcp attached

-- 
Hannu Krosing   http://www.2ndQuadrant.com
PostgreSQL Scalability and Availability 
   Services, Consulting and Training

Attachments:

MyServlet.java (text/x-java, 4.0K) download package com.zuehlke.aicp; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.io.Writer; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLWarning; import javax.naming.Context; import javax.naming.InitialContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.sql.DataSource; public class MyServlet extends HttpServlet { public static final String JDBC_URL = "jdbc:postgresql://localhost:5432/test"; public static final String QUERY = ""; private static final long serialVersionUID = 1L; private static final String USER = "test"; private static final String PWD = "test"; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException { try { writeStandardResponse(response); if (request.getParameter("direct") != null) { response.getOutputStream().print(query(direct())); } else if (request.getParameter("c3p0") != null) { response.getOutputStream().print(query(c3p0())); } else if (request.getParameter("proxool") != null) { response.getOutputStream().print(query(proxool())); } else if (request.getParameter("dbcp") != null) { response.getOutputStream().print(query(dbcp())); } } catch (IOException e) { e.printStackTrace(); } } private void writeStandardResponse(HttpServletResponse response) throws IOException { response.setContentType("text/html"); response.getOutputStream().println("<ul>"); response.getOutputStream().println("<li><a href='/ArrayInConnectionPool?direct'>direct</a></li>"); response.getOutputStream().println("<li><a href='/ArrayInConnectionPool?proxool'>proxool</a></li>"); response.getOutputStream().println("<li><a href='/ArrayInConnectionPool?c3p0'>c3p0</a></li>"); response.getOutputStream().println("<li><a href='/ArrayInConnectionPool?dbcp'>dbcp</a></li>"); response.getOutputStream().println("<ul>"); response.getOutputStream().println("<h3>Result (9 expected)</h3>"); } private String query(Connection conn) { StringBuilder out = new StringBuilder(); try { for (SQLWarning warn = conn.getWarnings(); warn != null; warn = warn.getNextWarning()) { out.append("SQL Warning:"); out.append("State : " + warn.getSQLState()); out.append("Message: " + warn.getMessage()); out.append("Error : " + warn.getErrorCode()); } Long[] array = { 1L, 2L }; PreparedStatement ps = conn.prepareStatement("SELECT * FROM arraySum(?, ?)"); ps.setLong(1, 3L); ps.setArray(2, conn.createArrayOf("bigint", array)); ps.execute(); ResultSet rs = ps.getResultSet(); while (rs.next()) { out.append(rs.getString(1)); } rs.close(); ps.close(); conn.close(); } catch (Exception e) { out.append(getStackTrace(e)); } return out.toString(); } private Connection c3p0() { return getJndiDataSource("jdbc/c3p0"); } private Connection proxool() { return getJndiDataSource("jdbc/proxool"); } private Connection dbcp() { return getJndiDataSource("jdbc/dbcp"); } private Connection getJndiDataSource(String name) { try { Context initContext = new InitialContext(); Context envContext = (Context) initContext.lookup("java:/comp/env"); DataSource ds = (DataSource) envContext.lookup(name); return ds.getConnection(); } catch (Exception e) { e.printStackTrace(); } return null; } private Connection direct() { try { Class.forName("org.postgresql.Driver"); return DriverManager.getConnection(JDBC_URL, USER, PWD); } catch (Exception e) { e.printStackTrace(); } return null; } public static String getStackTrace(Throwable aThrowable) { final Writer result = new StringWriter(); final PrintWriter printWriter = new PrintWriter(result); aThrowable.printStackTrace(printWriter); String html = result.toString(); html = html.replaceAll("\n", "<br />\n"); return html; } }

view thread (14+ messages)  latest in thread

Message-ID: <1239112973.7647.23.camel@huvostro>
Permalink:  ../1239112973.7647.23.camel@huvostro/
Also on:    postgresql.org/message-id/1239112973.7647.23.camel@huvostro

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: hannu@2ndQuadrant.com, pg@fastcrypt.com
  Subject: Re: What do people use for connection pooling with PostgreSQL  JDBC
  In-Reply-To: <1239112973.7647.23.camel@huvostro>
  References: <1236241901.12460.6.camel@huvostro> <491f66a50903050513r46ab0531h4892e973dec51f18@mail.gmail.com> <1239016398.8411.2.camel@huvostro> <491f66a50904060443o7e80fae8mfb6f403fb9a53467@mail.gmail.com> <1239093322.7647.9.camel@huvostro> <491f66a50904070324g19aee516vb5b1922b23450a27@mail.gmail.com> <1239110612.7647.15.camel@huvostro> <491f66a50904070639g6fe91d6dxa0f856e42e5cccce@mail.gmail.com> <1239112973.7647.23.camel@huvostro>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox