<?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>Anything But Ordinaryhibernarte</title>
	<atom:link href="http://abowow.com/tag/hibernarte/feed/" rel="self" type="application/rss+xml" />
	<link>http://abowow.com</link>
	<description>感性的光芒，理性的光辉</description>
	<lastBuildDate>Thu, 21 Apr 2011 07:10:40 +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>一个可以替代Hibernate的轻量化解决方案</title>
		<link>http://abowow.com/2009/04/an-light-substitution-for-hibernate/</link>
		<comments>http://abowow.com/2009/04/an-light-substitution-for-hibernate/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 13:36:27 +0000</pubDate>
		<dc:creator>Chaos</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[hibernarte]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.sharkwii.cn/?p=215</guid>
		<description><![CDATA[从同学那里搞了这个简单轻量的BaseDAO，其他对象的DAO继承自这个类，再写几个能用到的方法即可，相当方便。终于可以抛弃Hibernate了！ 代码较长，请点击下面的链接查看全文！ import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.List; import java.util.Properties; &#160; public abstract class BaseDAO &#123; &#160; protected Connection conn; protected static String driverClass; protected static String user; protected static String url; protected static String password; &#160; static &#123; //从数据库配置文件导入配置参数 Properties p = new Properties&#40;&#41;; try &#123; [...]]]></description>
			<content:encoded><![CDATA[<p>从同学那里搞了这个简单轻量的BaseDAO，其他对象的DAO继承自这个类，再写几个能用到的方法即可，相当方便。终于可以抛弃Hibernate了！</p>
<p>代码较长，请点击下面的链接查看全文！<br />
<span id="more-215"></span></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.Connection</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.DriverManager</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.ResultSet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.SQLException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.Statement</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Properties</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> BaseDAO <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">Connection</span> conn<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> driverClass<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> user<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> url<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> password<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">static</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//从数据库配置文件导入配置参数</span>
		<span style="color: #003399;">Properties</span> p <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Properties</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			p.<span style="color: #006633;">load</span><span style="color: #009900;">&#40;</span>BaseDAO.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getResourceAsStream</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/dbconfig.properties&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e1<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			e1.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		driverClass <span style="color: #339933;">=</span> p.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;driverClass&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		user <span style="color: #339933;">=</span> p.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		url <span style="color: #339933;">=</span> p.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;url&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		password <span style="color: #339933;">=</span> p.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//加载驱动类</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">Class</span>.<span style="color: #006633;">forName</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;com.mysql.jdbc.Driver&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">ClassNotFoundException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// TODO Auto-generated catch block</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> BaseDAO<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		openConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * 开启连接
	 */</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> openConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			conn <span style="color: #339933;">=</span> <span style="color: #003399;">DriverManager</span>.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span>url,user,password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">SQLException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// TODO Auto-generated catch block</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * 关闭连接
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> closeConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>conn<span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
				conn.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">SQLException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #666666; font-style: italic;">// TODO Auto-generated catch block</span>
				e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> executeUpdate<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> sql<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">Statement</span> stm <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			stm <span style="color: #339933;">=</span> conn.<span style="color: #006633;">createStatement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">SQLException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			stm.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>sql<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">SQLException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">ResultSet</span> executeQuery<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> sql<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">Statement</span> stm <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			stm <span style="color: #339933;">=</span> conn.<span style="color: #006633;">createStatement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">SQLException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #003399;">ResultSet</span> rs <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			rs <span style="color: #339933;">=</span> stm.<span style="color: #006633;">executeQuery</span><span style="color: #009900;">&#40;</span>sql<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">SQLException</span> e1<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			e1.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> rs<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unchecked&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #003399;">List</span> resultSetToList<span style="color: #009900;">&#40;</span><span style="color: #003399;">ResultSet</span> rs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>相关文章</h3>
<ul class="related_posts">
<li><a href="http://abowow.com/2008/12/magical-mandelbrot-set/" title="神奇的数学图形Mandelbrot set" rel="bookmark inlinks">神奇的数学图形Mandelbrot set</a><span class="count">( 4 )</span></li>
<li><a href="http://abowow.com/2008/12/a-few-basic-operations-of-hibernate/" title="[sdms项目文档]Hibernate框架下数据库更新操作" rel="bookmark inlinks">[sdms项目文档]Hibernate框架下数据库更新操作</a><span class="count">( 0 )</span></li>
<li><a href="http://abowow.com/2008/12/build-evironment-of-red5-and-flowplayer-on-linux/" title="[实验室项目]linux下red5 0.7.0与flowplayer 3.0.2流媒体平台的搭建" rel="bookmark inlinks">[实验室项目]linux下red5 0.7.0与flowplayer 3.0.2流媒体平台的搭建</a><span class="count">( 1 )</span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://abowow.com/2009/04/an-light-substitution-for-hibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[sdms项目文档]Hibernate框架下数据库更新操作</title>
		<link>http://abowow.com/2008/12/a-few-basic-operations-of-hibernate/</link>
		<comments>http://abowow.com/2008/12/a-few-basic-operations-of-hibernate/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 17:08:08 +0000</pubDate>
		<dc:creator>Chaos</dc:creator>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[hibernarte]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://sharkwii.heliohost.org/?p=9</guid>
		<description><![CDATA[package org.sdms.test; import org.hibernate.Transaction; import org.sdms.dao.Student; import org.sdms.dao.StudentDAO; public class UpdateTest { /** * @param args */ public static void main(String[] args) { StudentDAO dao =new StudentDAO(); Transaction tran=dao.getSession().beginTransaction(); // query Student bean=dao.findById("36060106"); // modify bean.setInterest("写BLOG"); // update dao.getSession().update(bean); tran.commit(); System.out.println("success!"); } } 相关文章 神奇的数学图形Mandelbrot set( 4 ) [实验室项目]linux下red5 0.7.0与flowplayer 3.0.2流媒体平台的搭建( 1 ) 一个可以替代Hibernate的轻量化解决方案( 0 [...]]]></description>
			<content:encoded><![CDATA[<pre name="code" class="java">package org.sdms.test;

import org.hibernate.Transaction;
import org.sdms.dao.Student;
import org.sdms.dao.StudentDAO;

public class UpdateTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		StudentDAO dao =new StudentDAO();
		Transaction tran=dao.getSession().beginTransaction();
		// query
		Student bean=dao.findById("36060106");
		// modify
		bean.setInterest("写BLOG");
		// update
		dao.getSession().update(bean);
		tran.commit();
		System.out.println("success!");
	}

}</pre>
<h3>相关文章</h3>
<ul class="related_posts">
<li><a href="http://abowow.com/2009/04/an-light-substitution-for-hibernate/" title="一个可以替代Hibernate的轻量化解决方案" rel="bookmark inlinks">一个可以替代Hibernate的轻量化解决方案</a><span class="count">( 0 )</span></li>
<li><a href="http://abowow.com/2008/12/build-evironment-of-red5-and-flowplayer-on-linux/" title="[实验室项目]linux下red5 0.7.0与flowplayer 3.0.2流媒体平台的搭建" rel="bookmark inlinks">[实验室项目]linux下red5 0.7.0与flowplayer 3.0.2流媒体平台的搭建</a><span class="count">( 1 )</span></li>
<li><a href="http://abowow.com/2008/12/endless-coding-and-reading-task/" title="上完了新东方，迎来了写不完的代码，看不完的RSS" rel="bookmark inlinks">上完了新东方，迎来了写不完的代码，看不完的RSS</a><span class="count">( 5 )</span></li>
<li><a href="http://abowow.com/2008/12/magical-mandelbrot-set/" title="神奇的数学图形Mandelbrot set" rel="bookmark inlinks">神奇的数学图形Mandelbrot set</a><span class="count">( 4 )</span></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://abowow.com/2008/12/a-few-basic-operations-of-hibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

