Received: from localhost (uranus.hub.org [200.46.204.60]) by postgresql.org (Postfix) with ESMTP id CCCF49FB229 for ; Tue, 21 Nov 2006 10:07:53 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.60]) (amavisd-new, port 10024) with ESMTP id 24917-04-2 for ; Tue, 21 Nov 2006 10:07:49 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id E378D9FB232 for ; Tue, 21 Nov 2006 10:06:36 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from mail01.enterprisedb.com (mail01.enterprisedb.com [63.246.7.168]) by svr4.postgresql.org (Postfix) with ESMTP id 4A90B5AFBB8 for ; Tue, 21 Nov 2006 09:46:00 +0000 (GMT) thread-index: AccNUdnWWOdyfLE8S2i085ejBisQOw== Content-Transfer-Encoding: 7bit Received: from [192.168.0.22] ([62.232.55.118]) by mail01.enterprisedb.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.1830); Tue, 21 Nov 2006 04:45:59 -0500 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.2757 Content-class: urn:content-classes:message Importance: normal Message-ID: <4562CAD1.5090603@enterprisedb.com> Date: Tue, 21 Nov 2006 09:45:53 +0000 From: "Heikki Linnakangas" User-Agent: Thunderbird 1.5.0.7 (X11/20060927) MIME-Version: 1.0 To: "Andreas" Cc: Subject: Re: Hello World References: <456295E2.3010209@gmx.net> In-Reply-To: <456295E2.3010209@gmx.net> Content-Type: multipart/mixed; boundary="------------070602090500010007090403" X-OriginalArrivalTime: 21 Nov 2006 09:45:59.0703 (UTC) FILETIME=[D9912A70:01C70D51] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/106 X-Sequence-Number: 16148 This is a multi-part message in MIME format. --------------070602090500010007090403 Content-Type: text/plain; format=flowed; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit Andreas wrote: > Hi, > > first of all I'll have to confess I don't know next to nothing at all > about JAVA, yet. > On the other hand I'm not exactly new to programming nor PostgreSQL either. > > Is there a "Hello World" level sample for jdbc with PG? I'd suggest to read the Java Tutorial by Sun: http://java.sun.com/docs/books/tutorial/ and after you got the basics, move on to the JDBC trail of the tutorial: http://java.sun.com/docs/books/tutorial/jdbc/index.html > Lets suppose I allready have a running PG with a db db_test that has a > few tables among which there is tbl_test in schema s. > The db-server might be 192.168.0.100. > User could be "user1" with password "pw1". > > What would be minimally needed to connect to db_test and read the > content of tbl_test to the console and logg off from PG. > > I'd prefer a complete sample code that could be dumped through javac. A sample attached. Save it to a file called JdbcTest.java, modify the server address, database name, table name etc. to suite your needs, and compile with "javac JdbcTest.java". To run, add postgresql.jar to your classpath. For example: java -cp path/to/postgresql.jar JdbcTest -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com --------------070602090500010007090403 Content-Type: text/x-java; name="JdbcTest.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="JdbcTest.java" import java.sql.*; public class JdbcTest { public static void main(String[] args) throws Exception { Class.forName("org.postgresql.Driver"); Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost/testdb", "username", "pw"); ResultSet rs = conn.prepareStatement("SELECT * FROM test").executeQuery(); while(rs.next()) System.out.println(rs.getString(1)); } } --------------070602090500010007090403--