X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 1B370537DC for ; Fri, 1 Apr 2005 02:17:55 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 35185-10 for ; Fri, 1 Apr 2005 01:17:53 +0000 (GMT) Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by svr1.postgresql.org (Postfix) with ESMTP id 45C72537D5 for ; Fri, 1 Apr 2005 02:17:52 +0100 (BST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 47CE030954; Fri, 1 Apr 2005 03:17:52 +0200 (MET DST) From: "Nico" X-Newsgroups: pgsql.interfaces.jdbc Subject: only postgresqsl in connection pool Date: Fri, 1 Apr 2005 03:16:46 +0200 Organization: Hub.Org Networking Services Lines: 101 Message-ID: X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2527 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 X-RFC2646: Format=Flowed; Original To: pgsql-jdbc@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=3.359 tagged_above=0 required=5 tests=FORGED_YAHOO_RCVD, PRIORITY_NO_NAME X-Spam-Level: *** X-Archive-Number: 200504/1 X-Sequence-Number: 12608 Hello, I have a servlet that runs on a postgresql-database. Or rather: that's what I thought... Let me start at the beginning. Originally, I made it in MySQL, but this didn't meet my requirements: the version installed on the server didn't support subqueries, so I switched to PostgreSQL. In the mean time, the database was created in MySQL and in PostgreSQL. When I get a connection, it connected to PostgreSQL. However, since I connect to the database through a connectionpool - I think - I only get connections from MySQL. So here is my question: how do I tell a java servlet I want a PostgreSQL connection - and not a MySQL connection- from a connection pool? I changed the username & password in the code for obvious security reasons... Kind regards, Nico. Here is my code for connecting to the database: protected final static String strDbdriver = "org.postgresql.Driver"; protected static void connect(String dbdriver, String methodname) throws DriverNotFoundException, ConnectionException { try { Class.forName(dbdriver); if(dbname==null) throw new menus.ConnectionException(dbdriver,"connect","dbname is null."); if(dbname.equals("")) throw new menus.ConnectionException(dbdriver, "connect", "dbname has empty string."); if(dbname.equals("null")) dbname="databasename"; int connattempts=0; while(connattempts<=5) { try { if(pool==null) { javax.naming.Context env=(javax.naming.Context) new javax.naming.InitialContext().lookup("java:comp/env"); pool=(DataSource)env.lookup("jdbc/"+dbname); } connection=pool.getConnection("username","password"); connattempts=8; } catch(NullPointerException fout) { disconnect(); connattempts++; } catch(SQLException fout) { disconnect(); connattempts++; } } if(connattempts!=8) { try { connection = DriverManager.getConnection("jdbc:postgresql://localhost/" + dbname + "?user=username&password=password"); } catch(SQLException fout) { throw new menus.ConnectionException(strDbdriver, methodname,"connection failed."); } } statementM1 = connection.createStatement(); statementM2 = connection.createStatement(); statementM3 = connection.createStatement(); statementM4 = connection.createStatement(); statementE1 = connection.createStatement(); statementE2 = connection.createStatement(); statementMeta = connection.createStatement(); } catch(ClassNotFoundException exception) { throw new DriverNotFoundException(dbdriver,methodname); } catch(SQLException fout) { disconnect(); throw new menus.ConnectionException(dbdriver,methodname,"cannot create statements"); } catch(NamingException fout) { disconnect(); throw new menus.ConnectionException(dbdriver, methodname,"namingexception: "+fout.getExplanation()); } }