Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 8E25A632BE0 for ; Tue, 27 Jul 2010 13:52:12 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 42071-08 for ; Tue, 27 Jul 2010 16:52:05 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outbound.vnet-inc.com (outbound.vnet-inc.com [216.146.104.103]) by mail.postgresql.org (Postfix) with ESMTP id 7C8F3632B4E for ; Tue, 27 Jul 2010 13:52:04 -0300 (ADT) Received: from [192.168.157.32] (te39.montanavision.com [216.220.28.39]) by outbound.vnet-inc.com (Postfix) with ESMTP id 9AFDC5AB7; Tue, 27 Jul 2010 10:51:58 -0600 (MDT) Message-ID: <4C4F0D03.3010907@ttc-cmc.net> Date: Tue, 27 Jul 2010 10:44:51 -0600 From: dmp User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.13) Gecko/20060417 X-Accept-Language: en-us, en MIME-Version: 1.0 To: fatih durum , pgsql-jdbc@postgresql.org Subject: Re: help References: In-Reply-To: Content-Type: multipart/mixed; boundary="------------020007080106000806060906" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.156 tagged_above=-10 required=5 tests=BAYES_05=-0.5, FILL_THIS_FORM_FRAUD_PHISH=0.334, T_FILL_THIS_FORM_SHORT=0.01 X-Spam-Level: X-Archive-Number: 201007/109 X-Sequence-Number: 20774 This is a multi-part message in MIME format. --------------020007080106000806060906 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit > > >fatih durum wrote: > > > >>> * have a problem of my connection to postgresql.* read your >>> documentation of your web site but * dont understand what am * >>> connected to postgresql.* downloaded the driver of jdbc but * >>> didnt find what do * this driver.Do you explain the connection >>> with an example ? >> >> Attached Java class example. Make sure the JDBC JAR file is in your classpath or just place in the JRE lib/ext directory. danap. --------------020007080106000806060906 Content-Type: text/plain; name="PostgreSQL_JDBC.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="PostgreSQL_JDBC.java" //================================================================= // PostgreSQL_JDBC Class //================================================================= // // This class is used to control the running of a generic // class to access the PostgreSQL database. // // << PostgreSQL_JDBC.java >> // //================================================================= // Copyright (C) 2005-2010 Dana M. Proctor // Version 1.02 07/27/2010 // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version // 2 of the License, or (at your option) any later version. This // program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See // the GNU General Public License for more details. You should // have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // (http://opensource.org) // //================================================================= // Revision History // Changes to the code should be documented here and reflected // in the present version number. Author information should // also be included with the original copyright author. //================================================================= // Version 1.0 12/23/2008 PostgreSQL Connection Main Application. // 1.1 02/13/2010 Generalized to be Used With Any Test Case. // 1.2 03/15/2010 Explicit Exception Output in main() & No // New Instance for Class.forName(). // 1.3 07/27/2010 Reviewed Just Updated Format Comments. // //----------------------------------------------------------------- // danap@dandymadeproductions.com //================================================================= //================================================================= // PostgreSQL_JDBC Application //================================================================= import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; /** * The PostgreSQL class is used to control the running of a generic * class to access the PostgreSQL database. Arguments -debug. * * @author Dana M. Proctor * @version 1.3 07/27/2010 */ class PostgreSQL_JDBC { // ============================================ // Creation of the necessary class instance. // ============================================= // None. //============================================================== // PostgreSQL_JDBC Constructor //============================================================== public PostgreSQL_JDBC(Connection con) { // Constructor Instances. // Perform Test or Do Something. /* try { // Do Insert whatever. } catch (SQLException sqle) { System.out.println("SQL Exeception" + sqle); } catch (IOException ioe) { System.out.println("Failed to Open File." + ioe); } */ } //============================================================ // Main public access point method for instantiating the // PostgreSQL_JDBC application. Arguments: database, username, // & password. //============================================================== public static void main(String[] args) { String host, database, username, password; Connection dbConnection; // Collect connection properties. and setup connection. host = "localhost"; dbConnection = null; if (args.length != 0) { database = args[0]; username = (args.length > 1) ? args[1] : null; password = (args.length > 2) ? args[2] : null; } else { database = ""; username = ""; password = ""; } try { Class.forName("org.postgresql.Driver"); } catch (ClassNotFoundException cne) {System.out.println("ClassNotFoundException" + cne.toString());} // Try to make a connection. try { dbConnection = DriverManager.getConnection("jdbc:postgresql://" + host + "/" + database, username, password); // Connection Good. if (dbConnection != null) { System.out.println("Connection Created"); // Go Do Something. new PostgreSQL_JDBC(dbConnection); // Close. dbConnection.close(); System.out.println("Connection Closed"); } } catch (SQLException sqle) {System.out.println("SQLExeception" + sqle.toString());} } } --------------020007080106000806060906--