Thread: Hello World
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? 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.
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 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)); } }
Have a look at this file: http://www.pensament.net/java/other_plugins.html#postgresql http://www.pensament.net/java/PostgreSQL_.java It shows how to connect and insert/query an image as bytea. Works on top of ImageJ http://rsb.info.nih.gov/ij/ , a public domain minimalistic java image processing application. Albert -- Albert Cardona Molecular Cell Developmental Biology University of California Los Angeles Tel +1 310 2067376 Programming: http://www.ini.unizh.ch/~acardona/trakem2.html Research: http://www.mcdb.ucla.edu/Research/Hartenstein/ Web design: http://www.pixelets.com
Andreas,
I was in a similar situation about two years ago and have, slowly, learned a bit about Java. Java itself is deceptively simple but to use it effectively, you will want to use one of the IDE platforms. I chose Eclipse over the others because it allows native access to SWT and JFace, and because it is open-source and free (like PostgreSQL). Eclipse has a pretty steep learning curve, but being a stubborn German, I stuck with it and now am able to do most things fairly easily. For the beginner, I would recommend investing in the Designer or RCP builder plug-in from Instantiations.
Working on my application, I realized that I could start by writing a basic, generic UI and then add custom features specific to my application later. I made the generic UI available at PgFoundry (the Komo project). It includes database access (password and other settings), as well as general utilities (back up, restore, vacuum). The code isn't perfect, but it works. Hopefully, this will serve as the "Hello World" application you are looking for. Here's the link http://pgfoundry.org/projects/komo-client/
Michael Schmidt
----- Original Message -----From: AndreasSent: Monday, November 20, 2006 11:00 PMSubject: [JDBC] Hello WorldHi,
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?
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.
---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faq
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. http://java.sun.com/docs/books/tutorial/jdbc/index.html Just follow this tutorial step by step. HTH ido
Could not find anything more "Hello World" than this :-) http://www.fankhausers.com/postgresql/jdbc/ --Imad www.EnterpriseDB.com On 11/21/06, Michael Schmidt <michaelmschmidt@msn.com> wrote: > > > > Andreas, > I was in a similar situation about two years ago and have, slowly, learned a > bit about Java. Java itself is deceptively simple but to use it > effectively, you will want to use one of the IDE platforms. I chose Eclipse > over the others because it allows native access to SWT and JFace, and > because it is open-source and free (like PostgreSQL). Eclipse has a pretty > steep learning curve, but being a stubborn German, I stuck with it and now > am able to do most things fairly easily. For the beginner, I would > recommend investing in the Designer or RCP builder plug-in from > Instantiations. > > Working on my application, I realized that I could start by writing a basic, > generic UI and then add custom features specific to my application later. I > made the generic UI available at PgFoundry (the Komo project). It includes > database access (password and other settings), as well as general utilities > (back up, restore, vacuum). The code isn't perfect, but it works. > Hopefully, this will serve as the "Hello World" application you are looking > for. Here's the link > http://pgfoundry.org/projects/komo-client/ > > Michael Schmidt > > > ----- Original Message ----- > From: Andreas > To: pgsql-jdbc@postgresql.org > Sent: Monday, November 20, 2006 11:00 PM > Subject: [JDBC] Hello World > > 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? > > 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. > > > ---------------------------(end of > broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq >