'datasource'에 해당되는 글 1

  1. 2009.03.06 jboss 에서 datasource 설정 하기 및 테스트
개발 | Posted by 1001엔젤 은우 아빠 2009.03.06 14:53

jboss 에서 datasource 설정 하기 및 테스트


\server\qnsolv\deploy\ oracle-ds.xml 파일 생성한다.

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
  <local-tx-datasource>
    <jndi-name>jdbc.dsCizle</jndi-name>
    <connection-url>jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1521:HEAVEN</connection-url>

    <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
    <user-name>user_xxx</user-name>
    <password>user_xxx00</password>
 
    <min-pool-size>10</min-pool-size>
    <max-pool-size>100</max-pool-size>
    <blocking-timeout-millis>5000</blocking-timeout-millis>
    <idle-timeout-minutes>15</idle-timeout-minutes>
    
   <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
    <metadata>
     <type-mapping>Oracle9i</type-mapping>
    </metadata>
  </local-tx-datasource>

</datasources>


jsp 소스


<%@page import="javax.transaction.Transaction"%>
<%@page import="javax.transaction.TransactionManager"%>
<%@page import="javax.transaction.UserTransaction"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>

<%@ page import="java.sql.Connection"%>
<%@ page import="javax.sql.DataSource"%>
<%@ page import="javax.naming.Context"%>
<%@ page import="javax.naming.InitialContext"%>
oracle test<br>
<%
Connection con=null;
Connection conmysql=null;
InitialContext ctx=null;
DataSource datasource=null;
TransactionManager tm=null;
ResultSet rs=null;
Statement stmt=null;
try {
ctx = new InitialContext();
tm = (TransactionManager)ctx.lookup("java:/TransactionManager");
tm.begin();
datasource = (DataSource) ctx.lookup("java:/jdbc.dsCizle");
out.println("<br>datasource==" + datasource);
con = datasource.getConnection();
out.println("<br>tm="+tm);
stmt = con.createStatement();
rs = stmt.executeQuery("select count(*) cnt from aa");
while(rs.next()){
out.println("<br/>start cnt="+rs.getString("cnt")+"<br/>");
}
stmt.executeUpdate("insert into aa(a) values(1)");
out.println("<br>after insert date<br>");
rs = stmt.executeQuery("select count(*) cnt from aa");
while(rs.next()){
out.println("insert cnt="+rs.getString("cnt"));
}
rs = stmt.executeQuery("select a from aa");
while(rs.next()){
out.println("<br>"+rs.getString("a"));
}
out.println("<br>");
tm.rollback();
rs = stmt.executeQuery("select count(*) cnt from aa");
while(rs.next()){
out.println("rollback cnt="+rs.getString("cnt"));
}
out.println("<br>after rollback date");
rs = stmt.executeQuery("select a from aa");
while(rs.next()){
out.println("<br>"+rs.getString("a"));
}
} catch (Exception e) {
try{
con.close();
ctx.close();
tm.rollback();
}catch(Exception e2){
}
e.printStackTrace();
}
%>