1 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, 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 { 62 if (st != null) { 63 st.close(); 64 } 65 if (cnx != null) { 66 cnx.close(); 67 } 68 } 69 } 70 | Popular Tags |