pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feed From: andy petrella <andy.petrella@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: newbie jdbc3 tiny example
Date: Tue, 18 Oct 2005 21:57:48 +0200
Message-ID: <7159e12c0510181257v7e4bb7fex@mail.gmail.com> (raw )
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 = null;
[...]
String hostname = "localhost:5432";
String database = "XXX";
String user ="abcdefg";
String psswd ="_______";
try {
Class.forName("org.postgresql.Driver"); //load the driver
db = DriverManager.getConnection("jdbc:postgresql://"+hostname+"/"+database+"?"+"user="+username+"&password="+password);
//connect to the db
dbmd = db.getMetaData(); //get MetaData to confirm connection
}catch (ClassNotFoundException e){
JOptionPane.showMessageDialog(null, e.getMessage(), "Error Driver pas
trouvé", JOptionPane.ERROR_MESSAGE);
}catch (SQLException e){
JOptionPane.showMessageDialog(null, e.getMessage(), "Error initialisation
connection", JOptionPane.ERROR_MESSAGE);
}
[...]
public PreparedStatement preparedAddDVD(){
try{
String insertion =
"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 => allocine
"1," + //1 visites a faire après
"0," + //0 cote
"?," + //imdb 7
"?," + //dir 8
"?," + //sce 9
"?," + //act 10
"default," +
"current_user," +
"current_timestamp," +
"?," + //acheté 11
"?," + //classement 12
")" +
";";
addDVD = 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'église, 17
] 4450 Slins
] mail: andy.petrella@gmail.com
] <licencié en math, info>
] dea S.I.G. (2005-2006)
\**/"""""""\**/"""""""\**/"""""""\**/"""""""\**/
view thread (2+ messages) latest in thread
Message-ID: <7159e12c0510181257v7e4bb7fex@mail.gmail.com>
Permalink: ../7159e12c0510181257v7e4bb7fex@mail.gmail.com/
Also on: postgresql.org/message-id/7159e12c0510181257v7e4bb7fex@mail.gmail.com
copy link · copy postgr.es
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: andy.petrella@gmail.com
Subject: Re: newbie jdbc3 tiny example
In-Reply-To: <7159e12c0510181257v7e4bb7fex@mail.gmail.com>
References: <7159e12c0510181257v7e4bb7fex@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox