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 3DBEED6D9D for ; Thu, 8 Sep 2005 05:17:24 -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 21769-02 for ; Thu, 8 Sep 2005 08:17:21 +0000 (GMT) Received: from mail.ecircle.de (mail.ecircle.de [195.140.186.200]) by svr1.postgresql.org (Postfix) with ESMTP id 10878D85E1 for ; Thu, 8 Sep 2005 05:17:18 -0300 (ADT) Received: from [192.168.1.110] (unknown [192.168.1.110]) by mail.ecircle.de (READY) with ESMTP id 66DF011DD12; Thu, 8 Sep 2005 10:17:18 +0200 (CEST) Subject: Re: simple insert operation From: Csaba Nagy To: =?iso-8859-9?Q?Ayd=FDn?= Toprak Cc: Postgres JDBC In-Reply-To: <431FEF3D.6050906@intengo.com> References: <431FEF3D.6050906@intengo.com> Content-Type: text/plain; charset=UTF-8 Message-Id: <1126167446.3026.9.camel@coppola.muc.ecircle.de> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Thu, 08 Sep 2005 10:17:26 +0200 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.303 required=5 tests=[AWL=-0.283, HOT_NASTY=0.586] X-Spam-Level: X-Archive-Number: 200509/20 X-Sequence-Number: 13805 Aydin, You're obviously beginner at Java too :-) The problem has nothing to do with JDBC, you must catch the Java exceptions which are declared to be thrown by the methods you use (the compilation error message is quite explicit about which ones), or declare them to be thrown by your code. Look up some Java tutorial, and/or use an intelligent IDE which highlights you the errors and possibly fixes them too automatically... IntelliJ is a good one (not free). Other than that, from a superficial check, I guess your code is Ok. Cheers, Csaba. On Thu, 2005-09-08 at 09:58, Aydın Toprak wrote: > Hii guys, > > 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... > > > here is my code for insertion... > > Class.forName("org.postgresql.Driver"); > String connectionStr = "jdbc:postgresql://localhost:5432/XXXX"; > Connection connection = > java.sql.DriverManager.getConnection(connectionStr, "XXXX", "XXXX"); > String sqlQuery = "INSERT INTO passTable (idCol , pass) VALUES > (3, 5)"; > PreparedStatement query = connection.prepareStatement(sqlQuery); > query.executeUpdate(); > connection.close(); > > but I cant compile it > > the errors > > ------------------------------------------------------------------------------------------- > form.java:26: unreported exception java.lang.ClassNotFoundException; > 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 > or decl > ared to be thrown > Connection connection = > java.sql.DriverManager.getConnection(con > nectionStr, "XXXX", "XXXX"); > > ^ > form.java:30: unreported exception java.sql.SQLException; must be caught > or decl > ared to be thrown > PreparedStatement query = > connection.prepareStatement(sqlQuery); > > ^ > form.java:31: unreported exception java.sql.SQLException; must be caught > or decl > ared to be thrown > query.executeUpdate(); > ^ > form.java:32: unreported exception java.sql.SQLException; must be caught > or decl > ared to be thrown > connection.close(); > ^ > 5 errors > ------------------------------------------------------------------------------------------- > > what is the problem I am stuck with it.. > > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq