source: ether_eccad/trunk/ECCAD_INTERFACE/WEB-INF/src/org/medias/eccad/persistance/jdbc/CodeDAOjdbc.java @ 70

Last change on this file since 70 was 70, checked in by cbipsl, 14 years ago

maj eccad V3.2

  • Property svn:executable set to *
File size: 2.1 KB
Line 
1package org.medias.eccad.persistance.jdbc;
2
3import java.sql.Connection;
4import java.sql.ResultSet;
5import java.sql.SQLException;
6import java.sql.Statement;
7import java.util.LinkedList;
8import java.util.List;
9
10import org.medias.eccad.persistance.dao.CodeDAO;
11import org.medias.eccad.persistance.exception.PersistanceException;
12
13public class CodeDAOjdbc extends GeneriqueDAOjdbc implements CodeDAO {
14
15        public List<String> getListCodeByGrille(long id_grille) throws PersistanceException {
16                Statement requete;
17                String sql;
18                Connection conn = getConnection();
19                List<String> code = new LinkedList<String>();
20               
21                try {
22                        requete = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
23//                      sql = " select num_code,legend_code"
24//                              + " from grille join codification using (id_codification)"
25//                              + " join code using (id_codification) where id_grille = " + id_grille + " order by num_code;";
26                        sql = " select number_code,legend_code" 
27                        + " from grille left join code on id_grille = num_code"
28                        + " where id_grille = " + id_grille + " order by number_code;";
29
30                        ResultSet resultat = requete.executeQuery(sql);
31                        String legend = "";
32                        while (resultat.next()) {
33                                legend = resultat.getString("legend_code");
34                                code.add(resultat.getString("number_code")+"-"+legend);
35                        }
36                        if (code.size() == 1) {
37                                code.set(0, "1-"+legend);
38                        }
39                }
40                catch (SQLException sqle) {
41                        throw new PersistanceException(sqle, "getListCodeByGrille");
42                }
43               
44                finally {
45                        closeConnection();
46                }
47               
48                return code;
49        }
50
51        public Long getNumberCode(long id_grille) throws PersistanceException {
52                Statement requete;
53                String sql;
54                Connection conn = getConnection();
55                Long code = null;
56               
57                try {
58                        requete = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
59                        sql = " select number_code" 
60                                + " from code where num_code = " + id_grille + ";";
61                       
62                        ResultSet resultat = requete.executeQuery(sql);
63                       
64                        if (resultat.next()) {
65                                code = resultat.getLong("number_code");
66                        }
67                }
68                catch (SQLException sqle) {
69                        throw new PersistanceException(sqle, "getListCodeByGrille");
70                }
71               
72                finally {
73                        closeConnection();
74                }
75               
76                return code;
77        }
78
79}
Note: See TracBrowser for help on using the repository browser.