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 7ACB7D87BE for ; Tue, 18 Oct 2005 20:42:56 -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 68930-04 for ; Tue, 18 Oct 2005 23:42:53 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.202]) by svr1.postgresql.org (Postfix) with ESMTP id 9DD00D8795 for ; Tue, 18 Oct 2005 20:42:54 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i5so102404wra for ; Tue, 18 Oct 2005 16:42:58 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=NeCSzEXzQX8L0mTzxPJrBHu/eUMjsv5L/dLDSEXGcB0btiBK52aIJSm2ELzZyD4u7p4ioO/xkT7SBaC88hGSC/h1evyByKbWIi22Uwt1xCDygtGl1Y0d7T8V+AI37mJGipD8op57URlABsbWvaKGRqjToIEEqaQfBWVGuwbs6IE= Received: by 10.54.119.20 with SMTP id r20mr352504wrc; Tue, 18 Oct 2005 16:42:58 -0700 (PDT) Received: by 10.54.105.13 with HTTP; Tue, 18 Oct 2005 16:42:57 -0700 (PDT) Message-ID: <3fccaa690510181642h644bd913mf212a9658713357e@mail.gmail.com> Date: Tue, 18 Oct 2005 17:42:57 -0600 From: Andres Olarte To: andy petrella , pgsql-jdbc@postgresql.org Subject: Re: newbie jdbc3 tiny example In-Reply-To: <7159e12c0510181257v7e4bb7fex@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <7159e12c0510181257v7e4bb7fex@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.194 required=5 tests=[AWL=-0.796, RCVD_BY_IP=0.024, WEIRD_QUOTING=1.966] X-Spam-Level: * X-Archive-Number: 200510/83 X-Sequence-Number: 14014 It seems ok to me. The idea with JDBC is that you don't have to deal with implementation specific classes, such as PGConnection, Jdbc3Connection, etc. It's all done on the background. If you are doing client side prepared statements, your code looks OK. Prepared Statements are a JDBC feature, common to all JDBC implementations, so you don't need any PG specific code. If you are trying to do Server side prepared statements, that's something else. But if you're new to this, stick to JDBC prepared statements, and keep your code portable that way. On 10/18/05, andy petrella wrote: > hi everyboy, > > I'm newbie with the jdbc and I wish to know how must be driven the > connection to a first preparedstatement using jdbc3 (an pg 8.0.3). > > My first throw (suspicious) was > > [...] > > private Connection db; > private Statement sql; > private DatabaseMetaData dbmd; > > private PreparedStatement addDVD =3D null; > > [...] > String hostname =3D "localhost:5432"; > String database =3D "XXX"; > String user =3D"abcdefg"; > String psswd =3D"_______"; > > > try { > Class.forName("org.postgresql.Driver"); //load the driver > db =3D > DriverManager.getConnection("jdbc:postgresql://"+hostname+"/"+database+"?= "+"user=3D"+username+"&password=3D"+password); > //connect to the db > dbmd =3D db.getMetaData(); //get MetaData to confirm connect= ion > }catch (ClassNotFoundException e){ > JOptionPane.showMessageDialog(null, e.getMessage(), "Error > Driver pas trouv=E9", JOptionPane.ERROR_MESSAGE); > }catch (SQLException e){ > JOptionPane.showMessageDialog(null, e.getMessage(), "Error > initialisation connection", JOptionPane.ERROR_MESSAGE); > } > > [...] > > public PreparedStatement preparedAddDVD(){ > try{ > String insertion =3D > "INSERT INTO FICHES.DVD" + > "id," + > "titre_o," + > "titre_f," + > "affiche," + > "duree," + > "genre," + > "resume," + > "visites," + > "cote," + > "imdb," + > "directeurs," + > "scenaristes," + > "acteurs," + > "possession_id," + > "possesseur," + > "acquis," + > "achete," + > "classement" + > "VALUES" + > "(" + > "default," + > "?," + //titreo > 1 > "?," + //sortie > 2 > "?," + //fr > 3 > "?," + //affiche > 4 > "?," + //duree > 5 > "?," + //genre > 6 > "resume," + //TODO null =3D> allocine > "1," + //1 visites a faire apr=E8s > "0," + //0 cote > "?," + //imdb > 7 > "?," + //dir > 8 > "?," + //sce > 9 > "?," + //act > 10 > "default," + > "current_user," + > "current_timestamp," + > "?," + //achet=E9 > 11 > "?," + //classement > 12 > ")" + > ";"; > addDVD =3D db.prepareStatement(insertion); > return addDVD; > }catch (SQLException e){ > JOptionPane.showMessageDialog(null, e.getMessage(), "Error > prepare addDVD", JOptionPane.ERROR_MESSAGE); > return null; > } > > [...] > > > And, what about the org.postgresql.jdbc3.Jdbc3Connection, > ... > the org.postgresql.PGConnection ... > > If it's little too long to explain someone can give me some links ? > > tks. > > > -- > /**\_____/**\_____/**\_____/**\_____/**\ > ] Signature : > ] Andy Petrella > ] Rue dessous l'=E9glise, 17 > ] 4450 Slins > > ] mail: andy.petrella@gmail.com > ] > ] dea S.I.G. (2005-2006) > \**/"""""""\**/"""""""\**/"""""""\**/"""""""\**/