Created
April 18, 2018 15:32
-
-
Save denispeyrusaubes/bb8d12942fc3a0e0dba9ef5e230d1439 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.retengr.service; | |
| import com.retengr.configuration.BanqueConfiguration; | |
| import com.retengr.configuration.DBConfiguration; | |
| import org.junit.BeforeClass; | |
| import org.junit.Test; | |
| import org.junit.runner.RunWith; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.context.ApplicationContext; | |
| import org.springframework.context.support.ClassPathXmlApplicationContext; | |
| import org.springframework.test.context.ContextConfiguration; | |
| import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |
| import java.sql.Connection; | |
| import java.sql.ResultSet; | |
| import java.sql.SQLException; | |
| import java.sql.Statement; | |
| @RunWith(SpringJUnit4ClassRunner.class) | |
| @ContextConfiguration(classes = {BanqueConfiguration.class, DBConfiguration.class}) | |
| public class DBTest { | |
| @Autowired | |
| private Connection connection; | |
| @Test | |
| public void displayData() { | |
| Statement st = null; | |
| try { | |
| st = connection.createStatement(); | |
| ResultSet rs = st.executeQuery("select * from CLIENT"); | |
| while (rs.next()) { | |
| System.out.println(rs.getString(1) + " " | |
| + rs.getString(2) + " " | |
| + rs.getString(3) ); | |
| } | |
| st.close(); | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } finally { | |
| try { | |
| st.close(); | |
| connection.close(); | |
| } catch (SQLException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment