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 45DB3D854F for ; Thu, 8 Sep 2005 05:24:32 -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 21029-05 for ; Thu, 8 Sep 2005 08:24:24 +0000 (GMT) Received: from mosaic02.mosaic.de (mosaic02.mosaic.de [195.247.16.18]) by svr1.postgresql.org (Postfix) with ESMTP id 58D21D853B for ; Thu, 8 Sep 2005 05:24:23 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mosaic02.mosaic.de (Postfix) with ESMTP id 3CD96778A7; Thu, 8 Sep 2005 10:25:16 +0200 (CEST) Received: from mosaic02.mosaic.de ([127.0.0.1]) by localhost (mosaic02.mosaic-ag.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 02708-05; Thu, 8 Sep 2005 10:25:15 +0200 (CEST) Received: by mosaic02.mosaic.de (Postfix, from userid 10) id F3B1F778AC; Thu, 8 Sep 2005 10:25:14 +0200 (CEST) Received: from [172.17.1.87] (aupc287.mosaic-ag.com [172.17.1.87]) by mailsrv.mosaic-ag.com (Postfix) with ESMTP id A40D5562EA; Thu, 8 Sep 2005 10:23:06 +0200 (CEST) Message-ID: <431FF4EA.7070508@mosaic-ag.com> Date: Thu, 08 Sep 2005 10:23:06 +0200 From: Roland Walter User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; de-AT; rv:1.7.5) Gecko/20041217 X-Accept-Language: de-DE,de,en MIME-Version: 1.0 To: =?UTF-8?B?QXlkxLFuIFRvcHJhaw==?= Cc: pgsql-jdbc@postgresql.org Subject: Re: simple insert operation References: <431FEF3D.6050906@intengo.com> In-Reply-To: <431FEF3D.6050906@intengo.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: mosaic-ag.com X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.357 required=5 tests=[AWL=-0.229, HOT_NASTY=0.586] X-Spam-Level: X-Archive-Number: 200509/21 X-Sequence-Number: 13806 Ayd=C4=B1n Toprak schrieb: > 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 > Class.forName("org.postgresql.Driver"); > 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(); >=20 > but I cant compile it >=20 > the errors >=20 > -------------------------------------------------------------------------= ------------------=20 >=20 > form.java:26: unreported exception java.lang.ClassNotFoundException;=20 > must be cau > ght 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=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=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 >=20 >=20 > what is the problem I am stuck with it.. >=20 The problem is, that all methods mentioned in the error messages throw exceptions. Exceptions in java must be catched in try-catch-block try { method(); ... } catch (ExceptionThrownByMethod e) { actOnExceptionOrNot(); ... =09 } You can omit the try-catch-block, if the method sorounding the called=20 method throws the exception: void doCallMethod() throws ExceptionThrownByMethod { method(); ... } But then you need to catch the Exception at the place where=20 doCallMethod() is called. Look in a documentation for the java programming language for more=20 information. --=20 Roland Walter phone: +49 (0) 22 25 / 88 2-41 1 MOSAIC SOFTWARE AG fax: +49 (0) 22 25 / 88 2-20 1 Am Pannacker 3 mailto: rwa (at) mosaic-ag (dot) com D-53340 Meckenheim http://www.mosaic-ag.com ------- L E G A L D I S C L A I M E R --------- Die Informationen in dieser Nachricht sind vertraulich und ausschliesslich fuer den Adressaten bestimmt. Kenntnisnahme durch Dritte ist unzulaessig. Die Erstellung von Kopien oder das Weiterleiten an weitere, nicht originaere und benannte Adressaten ist nicht vorgesehen und kann ungesetzlich sein. Die Meinungen in dieser Nachricht stellen lediglich die Meinungen des Senders dar. Falls Sie vermuten, dass diese Nachricht veraendert wurde, setzen Sie sich mit dem Absender in Verbindung. Der Absender uebernimmt ohne weitere Ueberpruefung keine Verantwortung fuer die Richtigkeit und Vollstaendigkeit des Inhalts. Unbefugte Empfaenger werden gebeten, die Vertraulichkeit der Nachricht zu wahren und den Absender sofort ueber einen Uebertragungsfehler zu informieren. ------------------------------------------------------