<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %> <%@ page import="java.sql.*, javax.sql.*, javax.naming.*" %> <% request.setCharacterEncoding("UTF-8"); //2020.09.25. 박민규- 캐릭터셋 설정 String uri = request.getRequestURI(); String type = request.getParameter("type"); String dsNm = request.getParameter("dsNm"); String driver = request.getParameter("driver"); String url = request.getParameter("url"); String user = request.getParameter("user"); String password = request.getParameter("password"); String sql = request.getParameter("sql"); if( type == null || type.equalsIgnoreCase("null") ) type = ""; if( dsNm == null || dsNm.equalsIgnoreCase("null") ) dsNm = ""; if( driver == null || driver.equalsIgnoreCase("null") ) driver = ""; if( url == null || url.equalsIgnoreCase("null") ) url = ""; if( user == null || user.equalsIgnoreCase("null") ) user = ""; if( password == null || password.equalsIgnoreCase("null") ) password = ""; if( sql == null || sql.equalsIgnoreCase("null") ) sql = ""; String msg = ""; Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; %> DataSource 확인

Check DataSource

WAS 유형 DataSource
Driver URL
User Password
<% if( type.equals("lookup") || type.equals("nonlookup") || type.equals("direct") ) { try { if( type.equals("lookup") ) { //lookup type (Tomcat, resin, Jrun ...) Context ctx = new InitialContext(); Context env = (Context)ctx.lookup("java:comp/env"); DataSource ds = (DataSource)env.lookup(dsNm); conn = ds.getConnection(); } else if( type.equals("nonlookup") ) { //nonlookup type (Jeus, WebLogic, WebSphere ...) Context ctx = new InitialContext(); DataSource ds = (DataSource)ctx.lookup(dsNm); conn = ds.getConnection(); } else { //direct Class.forName(driver); conn = DriverManager.getConnection(url, user, password); } if( conn == null ) msg = "Connection Fail!!!"; else msg = "Connection Success!!!"; } catch(Exception e) { msg = e.getMessage(); } finally { %>
Result(<%= type %>)
<%= msg %>
<% if( conn != null ) { %>
SQL
<% if( sql != null && !sql.equals("") ) { %> <% try { ps = conn.prepareStatement(sql); rs = ps.executeQuery(); ResultSetMetaData rsmd = rs.getMetaData(); int cnt = rsmd.getColumnCount(); out.println(""); for(int i = 0; i <= cnt; i++) { if( i == 0 ) out.println(""); else out.println(""); } int row_cnt = 0; while( rs.next() ) { out.println(""); for(int i = 0; i <= cnt; i++) { if( i == 0 ) out.println(""); else out.println(""); } out.println(""); } if( row_cnt == 0 ) { out.println(""); } } catch(Exception ee) { out.println(""); out.println(""); } %>
No" + rsmd.getColumnLabel(i) + "
" + ++row_cnt + "" + rs.getString(i) + "
조회 내역이 없습니다.
Error Message
" + ee.getMessage() + "
<% } if( rs != null ) try{ rs.close(); rs = null; } catch (Exception ex) {} if( ps != null ) try{ ps.close(); ps = null; } catch (Exception ex) {} if( conn != null ) try { conn.close(); conn = null; } catch(Exception e) {} } } } %>