KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > applimet > Dao


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: Dao.java,v 1.3 2004/04/28 15:32:38 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.beans.applimet;
27
28 import java.sql.Connection JavaDoc;
29 import java.sql.ResultSet JavaDoc;
30 import java.sql.SQLException JavaDoc;
31 import java.sql.Statement JavaDoc;
32 import java.sql.SQLException JavaDoc;
33 import javax.naming.Context JavaDoc;
34 import javax.naming.InitialContext JavaDoc;
35 import javax.naming.NamingException JavaDoc;
36 import javax.sql.DataSource JavaDoc;
37
38 public class Dao {
39     private Connection JavaDoc cnx = null;
40     private ResultSet JavaDoc rs = null;
41     private Statement JavaDoc st = null;
42
43     public Dao() throws NamingException JavaDoc, SQLException JavaDoc {
44         Context JavaDoc ctx = new InitialContext JavaDoc();
45         DataSource JavaDoc ds = (javax.sql.DataSource JavaDoc) ctx.lookup("jdbc_1");
46         cnx = ds.getConnection();
47     }
48
49     public String JavaDoc rechercherTousLesMarches() throws SQLException JavaDoc {
50         String JavaDoc ret = "";
51         st = cnx.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
52         rs = st.executeQuery("SELECT * FROM JT2_MARCHE");
53         if (rs.first()) {
54             do {
55                 ret = rs.getInt("IDMAR") + ":" + rs.getString("NOM") + "\n";
56             } while(rs.next());
57         }
58         return ret;
59     }
60
61     public void removeConnexion() throws SQLException JavaDoc {
62         if (st != null) {
63             st.close();
64         }
65         if (cnx != null) {
66             cnx.close();
67         }
68     }
69 }
70
Popular Tags