Hello Rafal : In order to use Jdbc and Spring,
you can use the JdbcTemplate provided by spring then you do not need to write so much "connection setup" codes cheers bb 2010/3/13 Rafał Laczek <rafal_lac...@wp.pl> > Hi, > > > The Spring is quite new for me but in my project I must use it to > extract data from database. > Bellow I send you code. > Unfortunately loading of the context should be left to the Spring > listener instead of this explicit creation. > > Could you help me please to change this code. > > Thank you very much for support. > > > Regards, > > Rafal > > > public class JdbcService{ > private static final Log log = LogFactory.getLog(JdbcService.class); > > ApplicationContext ac = new > ClassPathXmlApplicationContext("application-context.xml"); > > DataSource datasource = (DataSource) ac.getBean("ADataSource", > DataSource.class); > > public Map<String, List<ServiceMessageVO>> getAllServiceMessages() { > > Map<String, List<ServiceMessageVO>> ret = new HashMap<String, > List<ServiceMessageVO>>(); > > Connection c = null; > > try { > > c = datasource.getConnection(); > > if ( c == null ) { > > try { > > throw new Exception("Data source not found!"); > > } catch (Exception e) { > > e.printStackTrace(); > > } > > }else{ > > System.out.println("DATA SOURCE IS FOUND"); > > } > > > String sql = "SELECT sometging FROM TABLE"; > PreparedStatement pstm = (PreparedStatement) c.prepareStatement(); > ResultSet rs = pstm.executeQuery(sql); > while (rs.next()) {......... > > > -- > You received this message because you are subscribed to the Google > Groups "Java EE (J2EE) Programming with Passion!" group. > To post to this group, send email to > java-ee-j2ee-programming-with-passion@googlegroups.com > To unsubscribe from this group, send email to > java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com<java-ee-j2ee-programming-with-passion%2bunsubscr...@googlegroups.com> > For more options, visit this group at > > http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en -- You received this message because you are subscribed to the Google Groups "Java EE (J2EE) Programming with Passion!" group. To post to this group, send email to java-ee-j2ee-programming-with-passion@googlegroups.com To unsubscribe from this group, send email to java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en