X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 33DB5D8728 for ; Thu, 8 Sep 2005 12:02:54 -0300 (ADT) 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 20475-05 for ; Thu, 8 Sep 2005 15:02:47 +0000 (GMT) Received: from centos-02-ar.wavenet.com.ar (jazzparajesus.com.ar [200.49.155.17]) by svr1.postgresql.org (Postfix) with ESMTP id 4A8D9D7D3D for ; Thu, 8 Sep 2005 12:02:46 -0300 (ADT) Received: from [201.254.102.53] (helo=mi_servidor) by centos-02-ar.wavenet.com.ar with esmtpa (Exim 4.52) id 1EDNvE-0005Rn-W2; Thu, 08 Sep 2005 12:02:41 -0300 Subject: Re: simple insert operation From: Diego Gil To: =?iso-8859-9?Q?Ayd=FDn?= Toprak Cc: pgsql-jdbc@postgresql.org In-Reply-To: <431FEF3D.6050906@intengo.com> References: <431FEF3D.6050906@intengo.com> Content-Type: text/plain; charset=utf-8 Date: Thu, 08 Sep 2005 12:04:13 -0300 Message-Id: <1126191853.3004.9.camel@roadwarrior.adminsa.com> Mime-Version: 1.0 X-Mailer: Evolution 2.2.2 (2.2.2-5) Content-Transfer-Encoding: quoted-printable X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - centos-02-ar.wavenet.com.ar X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [47 12] X-AntiAbuse: Sender Address Domain - adminsa.com X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.929 required=5 tests=[AWL=-0.733, FORGED_RCVD_HELO=0.05, HOT_NASTY=0.586, RCVD_IN_NJABL_PROXY=1.026] X-Spam-Level: X-Archive-Number: 200509/22 X-Sequence-Number: 13807 Hi, The problem is that you never catch exceptions, specifically SQLException. It is more a Java problem that a PostgreSQL problem. Maybe you should read a little more about Java. http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html Look at the modified code below. Besides, it doesn't make sense to use PreparedStatement if don't use any variable inside. Regards, Diego. El jue, 08-09-2005 a las 10:58 +0300, Ayd=C4=B1n Toprak escribi=C3=B3: > Hii guys, >=20 > I am very newbie about postgresql and I am making practice, > however I couldnt been able to insert a simple item to my DB via jdbc... >=20 >=20 > here is my code for insertion... >=20 try { > Class.forName("org.postgresql.Driver"); } catch (java.lang.ClassNotFoundException nfe) { nfe.printStackTrace(); } try { > String connectionStr =3D "jdbc:postgresql://localhost:5432/XXXX"; > Connection connection =3D=20 > java.sql.DriverManager.getConnection(connectionStr, "XXXX", "XXXX"); > String sqlQuery =3D "INSERT INTO passTable (idCol , pass) VALUES=20 > (3, 5)"; > PreparedStatement query =3D connection.prepareStatement(sqlQuery)= ; > query.executeUpdate(); > connection.close(); } catch (java.sql.SQLException se) { se.printStackTrace(); } >=20 > but I cant compile it >=20 > the errors >=20 > -------------------------------------------------------------------------= ------------------ > form.java:26: unreported exception java.lang.ClassNotFoundException;=20 > must be caught or declared to be thrown > Class.forName("org.postgresql.Driver"); > ^ > form.java:28: unreported exception java.sql.SQLException; must be caught=20 > or decl > ared to be thrown > Connection connection =3D=20 > java.sql.DriverManager.getConnection(con > nectionStr, "XXXX", "XXXX"); > = =20 > ^ > form.java:30: unreported exception java.sql.SQLException; must be caught=20 > or decl > ared to be thrown > PreparedStatement query =3D=20 > connection.prepareStatement(sqlQuery); >=20 > ^ > form.java:31: unreported exception java.sql.SQLException; must be caught=20 > or decl > ared to be thrown > query.executeUpdate(); > ^ > form.java:32: unreported exception java.sql.SQLException; must be caught=20 > or decl > ared to be thrown > connection.close(); > ^ > 5 errors > -------------------------------------------------------------------------= ------------------ >=20 > what is the problem I am stuck with it.. >=20 >=20 >=20 >=20 >=20 > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? >=20 > http://www.postgresql.org/docs/faq >=20 >=20