<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>달콤 쌉싸래한 인생 &#187; JDBC</title>
	<atom:link href="http://jongsunkim.pe.kr/archives/category/programming/java/jdbc/feed" rel="self" type="application/rss+xml" />
	<link>http://jongsunkim.pe.kr</link>
	<description>Be fully awake if you want to dream</description>
	<lastBuildDate>Sat, 19 Nov 2011 08:34:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Tomcat &amp; Oracle DataSource 설정</title>
		<link>http://jongsunkim.pe.kr/archives/1107</link>
		<comments>http://jongsunkim.pe.kr/archives/1107#comments</comments>
		<pubDate>Sun, 11 Jul 2010 03:07:29 +0000</pubDate>
		<dc:creator>Kim Jong-seon</dc:creator>
				<category><![CDATA[JDBC]]></category>
		<category><![CDATA[JSP&Servlet]]></category>
		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://jongsunkim.pe.kr/?p=1107</guid>
		<description><![CDATA[1. conf/server.xml파일을 열고 &#60;GlobalNamingResources&#62;엘리먼트 안에 다음 내용 추가. 2. conf/context.xml에 추가 3. 코드 안에서는]]></description>
			<content:encoded><![CDATA[<p><strong>1. conf/server.xml파일을 열고 &lt;GlobalNamingResources&gt;엘리먼트 안에 다음 내용 추가.</strong></p>
<pre class="brush: xml; title: ; notranslate">

&lt;Resource name=&quot;jdbc/myoracle&quot; auth=&quot;Container&quot;
 type=&quot;javax.sql.DataSource&quot; driverClassName=&quot;oracle.jdbc.OracleDriver&quot;
 url=&quot;jdbc:oracle:thin:@localhost:1521:데이터베이스이름&quot;
 username=&quot;유저네임&quot; password=&quot;패스워드&quot; /&gt;
</pre>
<p><strong>2. conf/context.xml에 추가</strong></p>
<pre class="brush: xml; title: ; notranslate">

&lt;ResourceLink global=&quot;jdbc/myoracle&quot; name=&quot;jdbc/myoracle&quot; type=&quot;javax.sql.DataSource&quot;/&gt;
</pre>
<p><strong>3. 코드 안에서는</strong></p>
<pre class="brush: java; title: ; notranslate">

InitialContext ic = new InitialContext();
DataSource ds = (DataSource)ic.lookup(&quot;java:comp/env/jdbc/myoracle&quot;);
Connection con = ds.getConnection();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jongsunkim.pe.kr/archives/1107/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>select 쿼리</title>
		<link>http://jongsunkim.pe.kr/archives/1016</link>
		<comments>http://jongsunkim.pe.kr/archives/1016#comments</comments>
		<pubDate>Wed, 16 Jun 2010 03:11:39 +0000</pubDate>
		<dc:creator>Kim Jong-seon</dc:creator>
				<category><![CDATA[JDBC]]></category>

		<guid isPermaLink="false">http://jongsunkim.pe.kr/archives/1016</guid>
		<description><![CDATA[select 쿼리는 executeQuery() 메소드를 이용한다. executeQuery() 메소드는 ResultSet으로 리턴되며 ResultSet의 next() 등을 이용하여 결과를 보여주게된다.]]></description>
			<content:encoded><![CDATA[<p>select 쿼리는 executeQuery() 메소드를 이용한다.<br />
executeQuery() 메소드는 ResultSet으로 리턴되며<br />
ResultSet의 next() 등을 이용하여 결과를 보여주게된다.</p>
<pre class="brush: java; title: ; notranslate">

package step3;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import config.DbConfig;

public class TestJdbc3 {
 public static void main(String[] args) {
 Connection con = null;
 Statement stmt = null;
 ResultSet rs = null;    // select 조회 결과를 열어볼 수 있도록 추상메서드를 제공..

 try {
 Class.forName(DbConfig.driver);
 System.out.println(&quot;1. Driver Loading...&quot;);

 con = DriverManager.getConnection(DbConfig.url, DbConfig.user, DbConfig.pass);
 System.out.println(&quot;2. Connection...&quot;);

 stmt = con.createStatement();
 System.out.println(&quot;3. Statement...&quot;);

 String sql = &quot;select id, password, name, address from member&quot;;
 // Select 문은 executeQuery() 메소드를 이용한다
 rs = stmt.executeQuery(sql);    // ResultSet 으로 리턴되어짐

 // next() : 다음 행이 존재하면 true 아니면 false
 while(rs.next()){
 String id = rs.getString(1);
 String password = rs.getString(2);
 String name = rs.getString(3);
 String address = rs.getString(&quot;address&quot;);    // 컬러명으로도 가능하다.
 System.out.println(&quot;id : &quot; + id + &quot;, password : &quot; + password +
 &quot;, name : &quot; + name + &quot;, address : &quot; + address);
 }// whiles
 System.out.println(&quot;4. Query 실행...&quot;);

 } catch (ClassNotFoundException e) {
 e.printStackTrace();
 } catch (SQLException e) {
 e.printStackTrace();
 } finally {
 if(rs != null){
 try {
 rs.close();
 System.out.println(&quot;rs.close()&quot;);
 } catch (SQLException e) {
 e.printStackTrace();
 }
 }// if
 if(stmt != null){
 try {
 stmt.close();
 System.out.println(&quot;stmt.close()&quot;);
 } catch (SQLException e) {
 e.printStackTrace();
 }
 }// if
 if(con != null){
 try {
 con.close();
 System.out.println(&quot;con.close()&quot;);
 } catch (SQLException e) {
 e.printStackTrace();
 }
 }// if
 System.out.println(&quot;5. Close...&quot;);
 }// finally

 }// main
}// class
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jongsunkim.pe.kr/archives/1016/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JDBC step</title>
		<link>http://jongsunkim.pe.kr/archives/1007</link>
		<comments>http://jongsunkim.pe.kr/archives/1007#comments</comments>
		<pubDate>Mon, 14 Jun 2010 12:21:44 +0000</pubDate>
		<dc:creator>Kim Jong-seon</dc:creator>
				<category><![CDATA[JDBC]]></category>

		<guid isPermaLink="false">http://jongsunkim.pe.kr/?p=1007</guid>
		<description><![CDATA[* JDBC step 1. Driver Loading 2. Connection 3. Statement 4. Query 정의 및 실행 executeUpdate() : insert, delete, update executeQuery() : select : ResultSet 으로 리턴 5. Close()]]></description>
			<content:encoded><![CDATA[<p><strong>* JDBC step</strong></p>
<div>1. Driver Loading</div>
<div>2. Connection</div>
<div>3.  Statement</div>
<div>4. Query 정의 및 실행</div>
<ol>
<li>executeUpdate() :  insert, delete, update</li>
<li>executeQuery() : select :  ResultSet 으로 리턴</li>
</ol>
<div>5. Close()</div>
<div>
<pre class="brush: java; title: ; notranslate">
package step1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class TestJdbc1 {
    public static void main(String[] args) {
        String driver = &quot;oracle.jdbc.driver.OracleDriver&quot;;        // 1
        String url = &quot;jdbc:oracle:thin:@127.0.0.1:1521:xe&quot;;        // 2
        String user = &quot;pm&quot;;
        String pass = &quot;oracle&quot;;
        try {
            // 1.
            Class.forName(driver);
            System.out.println(&quot;1. driver loading&quot;);
            // 2.
            Connection con = DriverManager.getConnection(url, user, pass);
            System.out.println(&quot;2. Connection&quot;);
            Statement stmt = con.createStatement();
            System.out.println(&quot;3. Statement&quot;);
            String sql = &quot;insert into member(id, password, name, address) &quot; +
            &quot;values('lee', 'bbb', '이영표', '종로')&quot;;
            int result = stmt.executeUpdate(sql);
            // int result 리턴값은 영향을 준 row 의 수
            System.out.println(&quot;4. Query 실행--&gt; &quot; + result);
            stmt.close();
            con.close();
            System.out.println(&quot;5. Close...&quot;);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
}
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://jongsunkim.pe.kr/archives/1007/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

