From robson@netalfa.com.br Wed Jul 7 14:15:31 1999 Received: from paris.netalfa.com.br ([200.210.212.12]) by hub.org (8.9.3/8.9.3) with ESMTP id KAA32040 for ; Wed, 7 Jul 1999 10:15:31 -0400 (EDT) (envelope-from robson@netalfa.com.br) Received: from Designer2 ([200.210.212.30]) by paris.netalfa.com.br (8.9.2/8.9.2) with SMTP id LAA16914 for ; Wed, 7 Jul 1999 11:17:18 -0300 (EST) Message-ID: <004c01bec882$dfc536a0$1ed4d2c8@Designer2.netalfa.com.br> Reply-To: "Robson Martins" From: "Robson Martins" To: "pgsql-interfaces" Subject: How to access postgresql database using jdbc driver? Date: Wed, 7 Jul 1999 11:13:23 -0300 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0049_01BEC869.BA3C7C40" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 4.72.3110.5 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 This is a multi-part message in MIME format. ------=_NextPart_000_0049_01BEC869.BA3C7C40 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello all. My name is Robson. I'm starting on java language yet, and I'm having problems to access = postgre sql database with jdbc. I have PostgreSQL 6.5, JDK1.1.8, and a jdbc driver to JDK1.1.x I'm using the comands: Class.forName("postgresql.Driver"); -> to select the type of database Connection db =3D = DriverManager.getConnection("jdbc:postgresql://200.210.212.4:5432/imf", = "username", "password"); -> to connect to the database But i dont know how I check if worked, and I get a lot of errors. Anybody can send me a example .java that show me how to load the driver, = connect to the database, see if worked, create tables, and others, using = postgres 6.5? I didnt find on the web. Please anybody help me with this! I'm waiting any answer... Robson ( robson@netalfa.com.br ) ------=_NextPart_000_0049_01BEC869.BA3C7C40 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hello all.
My name is Robson.
I'm starting on java language yet, and=20 I'm having problems to access postgre sql = database=20 with jdbc.
I have PostgreSQL 6.5, JDK1.1.8, and a jdbc driver = to=20 JDK1.1.x
I'm using the comands:
 Class.forName("postgresql.Driver"); -> = to select=20 the type of database
 Connection db =3D=20 DriverManager.getConnection("jdbc:postgresql://200.210.212.4:5432/imf",=20 "username", "password"); -> to  connect to the = database
But i dont know how I check if worked, and I get a = lot of=20 errors.
Anybody can send me a example .java that show me how = to load=20 the driver, connect to the database, see if worked, create tables, and = others,=20 using postgres 6.5?
I didnt find on the web.
Please anybody help me with this!
I'm waiting any answer...
Robson ( robson@netalfa.com.br )

 
 
------=_NextPart_000_0049_01BEC869.BA3C7C40-- From benoit@ooc.com Wed Jul 7 14:39:25 1999 Received: from ooc.ooc.com (ooc.ooc.com [207.60.240.130]) by hub.org (8.9.3/8.9.3) with ESMTP id KAA36296 for ; Wed, 7 Jul 1999 10:39:25 -0400 (EDT) (envelope-from benoit@ooc.com) Received: from ooc.com (kirk.ooc.com [207.60.240.142]) by ooc.ooc.com (8.8.7/8.8.7) with ESMTP id KAA19953; Wed, 7 Jul 1999 10:42:54 -0400 Message-ID: <378366AA.F240A470@ooc.com> Date: Wed, 07 Jul 1999 10:39:44 -0400 From: Benoit Foucher Reply-To: benoit@ooc.com Organization: Object Oriented Concepts X-Mailer: Mozilla 4.61 (Macintosh; I; PPC) MIME-Version: 1.0 To: Robson Martins CC: pgsql-interfaces Subject: Re: [INTERFACES] How to access postgresql database using jdbc driver? References: <004c01bec882$dfc536a0$1ed4d2c8@Designer2.netalfa.com.br> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi Robson, What are the errors? I suggest you to read the JDBC section in the java tutorial (on java.sun.com web site), there's also code sample on: http://developer.java.sun.com/developer/codesamples/database/ For postresql specific issue concerning the JDBC driver you can have a look at the "Postgresql Programmer's Guide" (doc/programmer.ps) and the example programs which are in the pgsql/src/interfaces/jdbc/example directory... Regards, Benoit > Robson Martins wrote: > > Hello all. > My name is Robson. > I'm starting on java language yet, and I'm having problems to access > postgre sql database with jdbc. > I have PostgreSQL 6.5, JDK1.1.8, and a jdbc driver to JDK1.1.x > I'm using the comands: > Class.forName("postgresql.Driver"); -> to select the type of database > Connection db = > DriverManager.getConnection("jdbc:postgresql://200.210.212.4:5432/imf", > "username", "password"); -> to connect to the database > But i dont know how I check if worked, and I get a lot of errors. > Anybody can send me a example .java that show me how to load the > driver, connect to the database, see if worked, create tables, and > others, using postgres 6.5? > I didnt find on the web. > Please anybody help me with this! > I'm waiting any answer... > Robson ( robson@netalfa.com.br ) > > > -- Benoit Foucher mailto:benoit@ooc.com Object-Oriented Concepts, Inc. (trainee) 44 Manning Road Billerica, MA 01821 From teo@flex.ro Wed Jul 7 15:23:50 1999 Received: from flex.flex.ro ([193.230.255.4]) by hub.org (8.9.3/8.9.3) with ESMTP id LAA45453 for ; Wed, 7 Jul 1999 11:23:50 -0400 (EDT) (envelope-from teo@flex.ro) Received: from flex.ro (IDENT:teo@teo.flex.ro [193.230.255.3]) by flex.flex.ro (8.9.1/8.9.1) with ESMTP id RAA25026; Wed, 7 Jul 1999 17:23:20 +0300 Sender: teo@flex.flex.ro Message-ID: <37837265.1E270F2B@flex.ro> Date: Wed, 07 Jul 1999 15:29:41 +0000 From: Constantin Teodorescu Organization: FLEX Consulting X-Mailer: Mozilla 4.51 [en] (X11; I; Linux 2.2.9 i586) X-Accept-Language: en MIME-Version: 1.0 To: Robson Martins CC: pgsql-interfaces Subject: Re: [INTERFACES] How to access postgresql database using jdbc driver? References: <004c01bec882$dfc536a0$1ed4d2c8@Designer2.netalfa.com.br> Content-Type: multipart/mixed; boundary="------------F5AE6FF14FB5570D240AF39A" This is a multi-part message in MIME format. --------------F5AE6FF14FB5570D240AF39A Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit I'm attaching here a simple Java program that will open, create a table and query the table printing the results! yourdb database must be previously created! Best regards, -- Constantin Teodorescu FLEX Consulting Braila, ROMANIA --------------F5AE6FF14FB5570D240AF39A Content-Type: text/plain; charset=us-ascii; name="tutorial.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="tutorial.java" import java.io.*; import java.sql.*; public class tutorial { private Connection dc; private Statement st; public tutorial() { try { Class.forName("postgresql.Driver"); } catch (Exception e) { e.printStackTrace(); System.out.println("Cannot load PostgreSQL driver\n"+e.getMessage()); System.exit(-1); } } public boolean openDatabase() { boolean result; try { dc = DriverManager.getConnection("jdbc:postgresql://localhost/yourdb","yourname","yourpassword"); st = dc.createStatement(); result = true; } catch (Exception e) { e.printStackTrace(); System.out.println("Cannot connect to database\nError:"+e.getMessage()); result = false; } return result; } public void run() { System.out.println("Starting work!"); try { st.executeUpdate("create table people (id int4, name varchar(32))"); st.executeUpdate("insert into people values(1,'teo')"); st.executeUpdate("insert into people values(2,'peter')"); ResultSet rs = st.executeQuery("select id,name from people"); if ( rs != null) { while ( rs.next() ) { System.out.println(rs.getString("name")+" has id= "+rs.getString("id")); } rs.close(); } st.executeUpdate("drop table people"); } catch (SQLException sqle) { System.out.println("A SQL exception occured : "+sqle.getMessage()); } System.out.println("Finished!"); } public static void main(String argv[]) { tutorial task = new tutorial(); if ( task.openDatabase() ) task.run(); } } --------------F5AE6FF14FB5570D240AF39A--