01: /*
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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 4664 2004-04-28 15:32:38Z durieuxp $
23: * --------------------------------------------------------------------------
24: */
25:
26: package org.objectweb.jonas.jtests.beans.applimet;
27:
28: import java.sql.Connection;
29: import java.sql.ResultSet;
30: import java.sql.SQLException;
31: import java.sql.Statement;
32: import java.sql.SQLException;
33: import javax.naming.Context;
34: import javax.naming.InitialContext;
35: import javax.naming.NamingException;
36: import javax.sql.DataSource;
37:
38: public class Dao {
39: private Connection cnx = null;
40: private ResultSet rs = null;
41: private Statement st = null;
42:
43: public Dao() throws NamingException, SQLException {
44: Context ctx = new InitialContext();
45: DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc_1");
46: cnx = ds.getConnection();
47: }
48:
49: public String rechercherTousLesMarches() throws SQLException {
50: String ret = "";
51: st = cnx.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
52: ResultSet.CONCUR_READ_ONLY);
53: rs = st.executeQuery("SELECT * FROM JT2_MARCHE");
54: if (rs.first()) {
55: do {
56: ret = rs.getInt("IDMAR") + ":" + rs.getString("NOM")
57: + "\n";
58: } while (rs.next());
59: }
60: return ret;
61: }
62:
63: public void removeConnexion() throws SQLException {
64: if (st != null) {
65: st.close();
66: }
67: if (cnx != null) {
68: cnx.close();
69: }
70: }
71: }
|