Double requete (master-detail)
Bonjour,
Je me bas avec jdbc depuis plusieurs heures et là, je suis bloqué. Si quelqu'un a une solution au problème suivant, je lui serait très reconnaissant.
Voila mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
public static void main(String[] args) throws Exception {
String driverNameFB = "org.firebirdsql.jdbc.FBDriver";
Class.forName(driverNameFB);
String serverNameFB = "localhost/3050";
String mydatabaseFB = "C:\\data\\data.GDB";
String urlFB = "jdbc:firebirdsql:" + serverNameFB + ":" + mydatabaseFB;
String usernameFB = "SYSDBA";
String passwordFB = "masterkey";
DriverManager.setLoginTimeout(0);
Connection connectionFB = DriverManager.getConnection(urlFB, usernameFB, passwordFB);
//j'ai besoin du ResultSet.TYPE_SCROLL_INSENSITIVE dans mon projet
Statement stm = connectionFB.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT);
String sql = "select * from tableA";
ResultSet rs = stm.executeQuery(sql);
rs.first();
while (rs!=null && !rs.isAfterLast()) {
System.out.println(rs.getString("namea"));
Statement stm2 = connectionFB.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT);
String sql2 = "select * from tableB where bid="+rs.getString("ida");
ResultSet rs2 = stm2.executeQuery(sql2);
rs2.first();
while (rs2!=null && !rs2.isAfterLast()) {
System.out.println(" "+rs2.getString("nameb"));
rs2.next();
}
rs.next();
}
} |
voici le contenu de mes tables :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
Table A Table B
id namea id ida nameb
1 Table A : AAAA 1 1 Table b : aaaaa 1
2 Table A : BBBB 2 1 Table b : aaaaa 2
3 1 Table b : aaaaa 3
4 1 Table b : aaaaa 4
5 1 Table b : aaaaa 5
6 1 Table b : aaaaa 6
7 2 Table b : bbbbb 1
8 2 Table b : bbbbb 2
9 2 Table b : bbbbb 3 |
Et bien, j'ai beau tourner le problème dans tous les sens, la méthode rs.isAfterLast() retourne toujours true a la fin du traitement de rs2 :cry:. Comme si le second enregistrement de la table a n'existait pas.
je dois pas faire comme il faut (je débute avec java).
merci de votre aide
Olivier
Information complémentaire :
ce même code fonctionne correctement avec le driver MySQL. le seul problème est que j'ai besoin attaquer une base firebird :(