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 E6F23D975D for ; Tue, 18 Oct 2005 16:57:48 -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 97794-01 for ; Tue, 18 Oct 2005 19:57:45 +0000 (GMT) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.204]) by svr1.postgresql.org (Postfix) with ESMTP id 8EF10D96CE for ; Tue, 18 Oct 2005 16:57:46 -0300 (ADT) Received: by zproxy.gmail.com with SMTP id 8so1058136nzo for ; Tue, 18 Oct 2005 12:57:48 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=h1NzyhW5XMuNsjXM8tMVlEExaDfPDsdk36qVVCpCzli79lKtR50XMssY2Dsn2hWB6UeXGcQFi2aeMRfM5QL0gNBQvpw/ZIxZVKm+pdnpq8imTdobZSwNka3Y9s8udWrls4szoDAiKXqQxSE4i5QHvS3FnPbFnT3b8W80VIoZiYY= Received: by 10.37.2.46 with SMTP id e46mr1391359nzi; Tue, 18 Oct 2005 12:57:48 -0700 (PDT) Received: by 10.36.227.8 with HTTP; Tue, 18 Oct 2005 12:57:48 -0700 (PDT) Message-ID: <7159e12c0510181257v7e4bb7fex@mail.gmail.com> Date: Tue, 18 Oct 2005 21:57:48 +0200 From: andy petrella To: pgsql-jdbc@postgresql.org Subject: newbie jdbc3 tiny example MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_6280_6629768.1129665468211" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.364 required=5 tests=[AWL=-0.627, HTML_MESSAGE=0.001, RCVD_BY_IP=0.024, WEIRD_QUOTING=1.966] X-Spam-Level: * X-Archive-Number: 200510/79 X-Sequence-Number: 14010 ------=_Part_6280_6629768.1129665468211 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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+"/"+databa= se+"?"+"user=3D"+username+"&password=3D"+password); //connect to the db dbmd =3D db.getMetaData(); //get MetaData to confirm connection }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) \**/"""""""\**/"""""""\**/"""""""\**/"""""""\**/ ------=_Part_6280_6629768.1129665468211 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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         &nbs= p;     addDVD =3D null;  
   
 [...] 
        String hostname =3D "localh= ost:5432";
        String database =3D "XXX&qu= ot;;
        String user =3D"abcdefg&quo= t;;
        String psswd =3D"_______&qu= ot;;

       
        try {
            Class.fo= rName("org.postgresql.Driver"); //load the driver
            db =3D DriverManager.getConnection("jdbc:postgresql://"+hostname+"/= "+database+"?"+"user=3D"+username+"&passw= ord=3D"+password); //connect to the db
            dbmd =3D= db.getMetaData(); //get MetaData to confirm connection
        }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 i= nsertion =3D
            &nb= sp;       "INSERT INTO FICHES.DVD" +
            &nb= sp;       "id," +
            &nb= sp;       "titre_o," +
            &nb= sp;       "titre_f," +
            &nb= sp;       "affiche," +
            &nb= sp;       "duree," +
            &nb= sp;       "genre," +
            &nb= sp;       "resume," +
            &nb= sp;       "visites," +
            &nb= sp;       "cote," +
            &nb= sp;       "imdb," +
            &nb= sp;       "directeurs," +
            &nb= sp;       "scenaristes," +
            &nb= sp;       "acteurs," +
            &nb= sp;       "possession_id," +
            &nb= sp;       "possesseur," +
            &nb= sp;       "acquis," +
            &nb= sp;       "achete," +
            &nb= sp;       "classement" +
            &nb= sp;       "VALUES" +
            &nb= sp;       "(" +
            &nb= sp;       "default," +
            &nb= sp;       "?," + //titreo           &= nbsp;           &nbs= p; 1
            &nb= sp;       "?," + //sortie           &= nbsp;           &nbs= p; 2
            &nb= sp;       "?," + //fr            = ;            &n= bsp;    3
            &nb= sp;       "?," + //affiche           =              4
            &nb= sp;       "?," + //duree           &n= bsp;            = ;  5
            &nb= sp;       "?," + //genre           &n= bsp;            = ;  6
            &nb= sp;       "resume," + //TODO null =3D> allocine
            &nb= sp;       "1," + //1 visites a faire apr=E8s
            &nb= sp;       "0," + //0 cote
            &nb= sp;       "?," + //imdb           &nb= sp;            =    7
            &nb= sp;       "?," + //dir           &nbs= p;            &= nbsp;   8
            &nb= sp;       "?," + //sce           &nbs= p;            &= nbsp;   9
            &nb= sp;       "?," + //act           &nbs= p;            &= nbsp;   10
            &nb= sp;       "default," +
            &nb= sp;       "current_user," +
            &nb= sp;       "current_timestamp," +
            &nb= sp;       "?," + //achet=E9           = ;            &n= bsp; 11
            &nb= sp;       "?," + //classement          &nb= sp;          12
            &nb= sp;       ")" +
            &nb= sp;       ";";
            addDVD = =3D db.prepareStatement(insertion);
            return a= ddDVD;
        }catch (SQLException e){
            JOptionPane.showMessageDialog(null, e.getMessage(), "Error prepare addDVD", JOptionPane.ERROR_MESSAGE);
            return n= ull;
        }

[...]


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.


--
/**\_____/**\_____/**\_____/**\_____/**\
]=             &nb= sp;           Signat= ure :
]           &nb= sp;        Andy Petrella
]          &n= bsp;  Rue dessous l'=E9glise, 17
]     &nb= sp;            =     4450 Slins           &nbs= p;            &= nbsp;     
]       mail: andy.petrella@gmail.com
]    &nb= sp;       <licenci=E9 en math, info&g= t;
]           &n= bsp; dea S.I.G. (2005-2006)
\**/""""""&qu= ot;\**/"""""""\**/"""&quo= t;"""\**/"""""""\**/ ------=_Part_6280_6629768.1129665468211--