public class MySQLConnectionTest {
private static final String DRIVER ="com.mysql.jdbc.Driver";
private static final String URL ="jdbc:mysql://localhost:3305/hamansuk?characterEncoding=utf8";
private static final String USER = "1111";
private static final String PW = "1111" ;
private static final Logger logger =LoggerFactory.getLogger(MySQLConnectionTest.class);
@Test
public void testConnection() throws Exception{
Class.forName(DRIVER);
try(Connection con =DriverManager.getConnection(URL, USER, PW)){
System.out.println(con);
//logger.info(con);
}catch(Exception e){
}
}
}
public class OracleConnectionTest {
private static final String DRIVER ="oracle.jdbc.driver.OracleDriver";
private static final String URL ="jdbc:oracle:thin:@localhost:1521:xe";
private static final String USER = "spring";
private static final String PW = "1234" ;
@Test
public void testConnection() throws Exception{
Class.forName(DRIVER);
try(Connection con =DriverManager.getConnection(URL, USER, PW)){
System.out.println(con);
}catch(Exception e){
e.printStackTrace();
}
}
}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:src/main/webapp/WEB-INF/spring/**/*.xml"})
public class MyBatisTest {
@Inject
private SqlSession sqlSession;
@Inject
private SqlSessionFactory factory;
@Inject
private DataSource ds;
private static final Logger logger=LoggerFactory.getLogger(MyBatisTest.class);
@Test
public void testDataSource(){
try(Connection con =ds.getConnection()){
logger.info("DataSource : " +con);
}catch(Exception e){
e.printStackTrace();
}
}
@Test
public void testFactory(){
logger.info( " SqlSessionFactory : " +factory.toString());
}
//@Test
public void mysqlTestSession() throws Exception {
try (SqlSession session =factory.openSession()){
logger.info("***********************MySQL************************");
logger.info( " sqlSession : " +sqlSession.toString());
logger.info( " factory.openSession() : " +session.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void oralceTestSession() throws Exception {
try (SqlSession session =factory.openSession()){
logger.info("***********************ORACLE************************");
logger.info( " sqlSession : " +sqlSession.toString());
logger.info( " factory.openSession() : " +session.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
댓글 ( 4)
댓글 남기기