Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 6CDB6632E69 for ; Tue, 7 Apr 2009 11:03:09 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 04938-06 for ; Tue, 7 Apr 2009 11:03:06 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.televork.ee (mail.televork.ee [81.21.241.190]) by mail.postgresql.org (Postfix) with ESMTP id 090F163280E for ; Tue, 7 Apr 2009 11:03:05 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mail.televork.ee (Postfix) with ESMTP id 423AA185F6F; Tue, 7 Apr 2009 17:03:02 +0300 (EEST) X-Virus-Scanned: at mail.televork.ee Received: from mail.televork.ee ([81.21.241.190]) by localhost (mail.televork.ee [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aEiw06qxxGeX; Tue, 7 Apr 2009 17:02:54 +0300 (EEST) Received: from [127.0.0.1] (81-21-242-98.televork.ee [81.21.242.98]) by mail.televork.ee (Postfix) with ESMTP id 2B1D9185F6E; Tue, 7 Apr 2009 17:02:54 +0300 (EEST) Subject: Re: What do people use for connection pooling with PostgreSQL JDBC From: Hannu Krosing To: Dave Cramer Cc: pgsql-jdbc@postgresql.org 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> Content-Type: multipart/mixed; boundary="=-ZpwyC9aBJCul9laUBfC1" Date: Tue, 07 Apr 2009 17:02:53 +0300 Message-Id: <1239112973.7647.23.camel@huvostro> Mime-Version: 1.0 X-Mailer: Evolution 2.24.3 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200904/14 X-Sequence-Number: 19461 --=-ZpwyC9aBJCul9laUBfC1 Content-Type: text/plain Content-Transfer-Encoding: 7bit On Tue, 2009-04-07 at 09:39 -0400, Dave Cramer wrote: > > > On Tue, Apr 7, 2009 at 9:23 AM, Hannu Krosing > wrote: > > On Tue, 2009-04-07 at 06:24 -0400, Dave Cramer wrote: > > > > > > On Tue, Apr 7, 2009 at 4:35 AM, Hannu Krosing > > > 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 --=-ZpwyC9aBJCul9laUBfC1 Content-Disposition: attachment; filename="MyServlet.java" Content-Type: text/x-java; name="MyServlet.java"; charset="UTF-8" Content-Transfer-Encoding: 7bit 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("
    "); response.getOutputStream().println("
  • direct
  • "); response.getOutputStream().println("
  • proxool
  • "); response.getOutputStream().println("
  • c3p0
  • "); response.getOutputStream().println("
  • dbcp
  • "); response.getOutputStream().println("
      "); response.getOutputStream().println("

      Result (9 expected)

      "); } 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", "
      \n"); return html; } } --=-ZpwyC9aBJCul9laUBfC1--