blah blah

tomcat, datasource, rowset 작업 메모

간단한 기능 구현할 일있어서 jdbc/jsp 코딩 중. 자바 코딩 안해본지 오래되서 생쇼 중. 생쇼 재방 막기 위해 잠깐 메모.

테스트 피씨에 우선 tomcat 6.0.* 다운 받아서 설치하고 jndi 이용하기 위해 datasource 설정

$CATALINA_HOME/conf/context.xml
<Resource name="jdbc/hjsmdm" auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@***:1521:dev"
username="scott" password="tiger" maxActive="20" maxIdle="10"
maxWait="-1"/>

WEB/INF/web.xml
<resource-ref>
<description>Oracle Datasource example</description>
<res-ref-name>jdbc/dev</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

jdk 6.* 라서 rowset 지원될거라 생각하고 사용 … 엉성하지만 작동은 하네.
개명한 시대에 이 무슨 무식한 짓꺼리냐 … ㅡ..ㅡㆀ
<%!
private CachedRowSet getInfo(String seg1, String seg2) throws Exception {
Connection con = null;
CachedRowSet crs = new CachedRowSetImpl();
StringBuffer sb = new StringBuffer();
sb.append("select ... ");
sb.append("from bes_history bh ");
sb.append("where bh.segment1 = ? ");
try{
con = getConnection();
crs.setCommand(sb.toString());
crs.setString(1, seg1);
crs.execute(con);
}finally{
if (con!=null) {
try{ con.close(); } catch(Exception ignored){}
}
}

return crs;
}
...
CachedRowSet crs = getInfo(subjCd, itemCd);
while(crs.next()) {
out.println(crs.getString("attribute1"));
}
%>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s