﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-程序员成长史-随笔分类-JDBC</title><link>http://www.blogjava.net/Good-Game/category/24761.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 21 Sep 2007 11:43:00 GMT</lastBuildDate><pubDate>Fri, 21 Sep 2007 11:43:00 GMT</pubDate><ttl>60</ttl><item><title>原创小框架: 动态面向对象数据库操作(不要影射类哦)</title><link>http://www.blogjava.net/Good-Game/archive/2007/09/21/147110.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Fri, 21 Sep 2007 06:46:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2007/09/21/147110.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/147110.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2007/09/21/147110.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/147110.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/147110.html</trackback:ping><description><![CDATA[
		<p>
				<font color="#ff0000">BUG修订 09-21 15:44<br /></font>
				<font color="#000000">   时间类不能Update 问题 (如果在上面时间前下载那请从新下载)</font>
		</p>
		<p> </p>
		<p>在上一版本有大改动 <a class="postTitle2" id="homepage1_HomePageDays_DaysList_ctl00_DayItem_DayList_ctl00_TitleUrl" href="/Good-Game/archive/2007/09/19/146387.html">自用小框架:DB工厂</a>  <br />         1.  添加 jdbc  事物<br />         2.  结构更合理<br />         3.  速度加快<br /><br /><strong><font color="#ffa500">工具简单说明</font></strong><br />      脱离 DB 影射包 java 数据类 ,动态在内存中生成 动态数据类 ( 使用BeanUtils的DyanBean类 )      .<br />      操作DB 面向对象操作(当然是动态^_^)<br />   <font color="#008000">  </font><font color="#808080"> 为了更实用 我用了张 50多属性的大表进行测试.阅读起来可能有点困难,希望大家海涵. <br /></font><strong><font color="#ffa500">version</font></strong> <br />   jdk 1.4<br /><br /><font color="#ffa500"><strong>下载<br /></strong>      <a href="/Files/Good-Game/DyanDBUtils.rar">DyanDBUtils.rar</a></font><br /><br /><font color="#ffa500"><strong>包文件说明 :</strong></font><br />         Config   :  JDBC 需要的 驱动 密码等 <br />         DBResources :   根据Config给出 Connection ,  PreparedStatement<br />         DynaClass :  根据元数据 和 table 给出 动态BasicDynaClass <br />         SQLSpelling : 给出 sql 语句和 sql语句中 ?  的值 ,格式为 List : lise.get(0)为sql语句 后其他为值  <br />         DyanDBUtils.java : 为本Util主要入口点 也是运行点<br /><br /><font color="#ffa500"><strong>数据库表  z_jcyy_basepersonnel<br /></strong></font>      有53个属性 (什么类型都有)<br />      4 个不为空属性 personid , workno , depotid ,  hname     <br /><br /><strong><font color="#ffa500">测试</font></strong><br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #0000ff">package</span>
				<span style="COLOR: #000000"> DyanDBUtils.test;<br /><br /><br /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> java.util.Iterator;<br /><br /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> org.apache.commons.beanutils.BeanUtils;<br /><br /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> DyanDBUtils.DyanDBUtils;<br /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> junit.framework.TestCase;<br /><br /></span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> testUtil </span>
				<span style="COLOR: #0000ff">extends</span>
				<span style="COLOR: #000000"> TestCase {<br />    </span>
				<span style="COLOR: #0000ff">static</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">private</span>
				<span style="COLOR: #000000"> DyanDBUtils dyd </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">  DyanDBUtils.getDyanDBUtil() ;<br />    </span>
				<span style="COLOR: #0000ff">static</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">private</span>
				<span style="COLOR: #000000"> Object obj </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">null</span>
				<span style="COLOR: #000000"> ;<br />  <font color="#008000">  //SELECT</font><br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> testSelete()</span>
				<span style="COLOR: #0000ff">throws</span>
				<span style="COLOR: #000000"> Exception{<br />        dyd.setIsShowSQL(</span>
				<span style="COLOR: #0000ff">true</span>
				<span style="COLOR: #000000">);<br />        </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">(Iterator it </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> dyd.select(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">select t.*, t.rowid from z_jcyy_basepersonnel t where t.personid = '0301003719'</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">).iterator();<br />                    it.hasNext();){<br />            Object obj </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> it.next();</span>
				<span style="COLOR: #000000">
						<br />        }<br />    }<br />    <font color="#006400">//INSERT</font><br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> testInsert()</span>
				<span style="COLOR: #0000ff">throws</span>
				<span style="COLOR: #000000"> Exception{<br />        obj </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> dyd.getDyanDBBean(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">z_jcyy_basepersonnel</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />            BeanUtils.setProperty(obj,</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">personid</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">1000</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />            BeanUtils.setProperty(obj,</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">workno</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">2000</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />            BeanUtils.setProperty(obj,</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">depotid</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">300</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />            BeanUtils.setProperty(obj,</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">hname</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">刘凯毅</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />        dyd.insert(obj);   <font color="#006400">//INSERT </font></span>
				<span style="COLOR: #000000">
						<br />    }<br /><br />  <font color="#006400"> //UPDATE</font><br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> testUpdate()</span>
				<span style="COLOR: #0000ff">throws</span>
				<span style="COLOR: #000000"> Exception{<br />        BeanUtils.setProperty(obj,</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">hname</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">思考..</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />        dyd.updateOrInsert(obj); <font color="#006400">//UPDATE</font></span>
				<span style="COLOR: #000000">
						<br />    }<br /><font color="#006400">//DELECT</font><br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> testDelete()</span>
				<span style="COLOR: #0000ff">throws</span>
				<span style="COLOR: #000000"> Exception{<br />        dyd.delete(obj);<font color="#006400">//DELECT</font></span>
				<span style="COLOR: #000000">
						<br />        System.out.println(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">******************************************</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />    }<br />    <br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> testCommit()</span>
				<span style="COLOR: #0000ff">throws</span>
				<span style="COLOR: #000000"> Exception{<br />        dyd.openCommit() ;<br />        Object obj </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> dyd.select(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">select t.*, t.rowid from z_jcyy_basepersonnel t where t.personid ='0301003719' </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">).get(</span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">);<br />        <br />        BeanUtils.setProperty(obj,</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">hname</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">刘凯毅</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />        dyd.updateOrInsert(obj);<br /><br />        BeanUtils.setProperty(obj,</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">workno</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #0000ff">null</span>
				<span style="COLOR: #000000">); </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">不可为空</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">        dyd.updateOrInsert(obj);<br />        <br />        dyd.colseCommit();<br />        testSelete();<br />    }<br />    <br />}<br /></span>
		</div>
		<p>
				<br />
				<br />
				<strong>
						<font color="#ffa500">测试测试结果 <font color="#0000ff">(注意: <font color="#a52a2a">开头的 <span style="COLOR: #000000"><font color="#a52a2a">李家佳</font></span> </font><font color="#a52a2a">3719  和后面的 3719  没变 就是事物的结果</font>)<br /></font></font>
				</strong>
		</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #000000">李家佳 </span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">3719</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">insert</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">into</span>
				<span style="COLOR: #000000"> z_jcyy_basepersonnel( depotid,drivekm,hname,hundreds,personid,resbaseknowledge,rescheck,resctrl,resproknowledge,ressaferules,roomarea,safekm,status,workno) </span>
				<span style="COLOR: #0000ff">values</span>
				<span style="COLOR: #000000">( ?,?,?,?,?,?,?,?,?,?,?,?,?,?)<br /></span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">
						<font color="#006400">//<font color="#008000">刘凯毅 <font style="BACKGROUND-COLOR: #eeeeee"></font></font><span style="FONT-WEIGHT: bold; COLOR: #800000"><font color="#008000">2000</font>   </span>print insert</font>
				</span>
				<span style="COLOR: #000000">
						<br />
						<strong>
								<font color="#006400">//</font>
						</strong>
						<font color="#006400">思考.. </font>
				</span>
				<font color="#006400">
				</font>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">
						<font color="#006400">2000 </font>   <font color="#006400"> print update</font></span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">delete</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> z_jcyy_basepersonnel </span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #808080">=</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #808080">and</span>
				<span style="COLOR: #000000"> personid</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">?</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #808080">******************************************</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">delete</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> z_jcyy_basepersonnel </span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #808080">=</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #808080">and</span>
				<span style="COLOR: #000000"> personid</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">?<br /></span>
				<span style="COLOR: #0000ff">insert</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">into</span>
				<span style="COLOR: #000000"> z_jcyy_basepersonnel( beginworktime,depotid,deptid,dob,drivekm,drivelocotype,dynamicinfo,dynamicinfo2,dynamicinfo3,eductionlevel,folk,hname,hundreds,marrystatus,minordriveno,nativeplace,personid,political,postid,promoteminordriverdate,resbaseknowledge,rescheck,resctrl,resproknowledge,ressaferules,roomarea,safebeginday,safekm,sex,status,techniclevel,workno) </span>
				<span style="COLOR: #0000ff">values</span>
				<span style="COLOR: #000000">( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)<br /></span>
				<span style="COLOR: #0000ff">delete</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">from</span>
				<span style="COLOR: #000000"> z_jcyy_basepersonnel </span>
				<span style="COLOR: #0000ff">where</span>
				<span style="COLOR: #000000"> </span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #808080">=</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">1</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #808080">and</span>
				<span style="COLOR: #000000"> personid</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">?<br /></span>
				<span style="COLOR: #0000ff">insert</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">into</span>
				<span style="COLOR: #000000"> z_jcyy_basepersonnel( beginworktime,depotid,deptid,dob,drivekm,drivelocotype,dynamicinfo,dynamicinfo2,dynamicinfo3,eductionlevel,folk,hname,hundreds,marrystatus,minordriveno,nativeplace,personid,political,postid,promoteminordriverdate,resbaseknowledge,rescheck,resctrl,resproknowledge,ressaferules,roomarea,safebeginday,safekm,sex,status,techniclevel) </span>
				<span style="COLOR: #0000ff">values</span>
				<span style="COLOR: #000000">( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)<br /><font color="#ff0000">java.sql.SQLException: </font>ORA</span>
				<span style="COLOR: #808080">-</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">01400</span>
				<span style="COLOR: #000000">: 无法将 </span>
				<span style="COLOR: #0000ff">NULL</span>
				<span style="COLOR: #000000"> 插入 ("JCYY"."Z_JCYY_BASEPERSONNEL"."WORKNO") <font color="#006400">//事物运行良好 哦</font><br /><br /><span style="COLOR: #000000">李家佳 </span><span style="FONT-WEIGHT: bold; COLOR: #800000">3719 </span></span>
		</div>
		<p>总结<br /><font color="#008000">事物 解决了 还有多表问题 大家多给点鼓励哦 ^_^</font> <br /><br /></p>
<img src ="http://www.blogjava.net/Good-Game/aggbug/147110.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2007-09-21 14:46 <a href="http://www.blogjava.net/Good-Game/archive/2007/09/21/147110.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>自用小框架:DB工厂</title><link>http://www.blogjava.net/Good-Game/archive/2007/09/19/146387.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Wed, 19 Sep 2007 03:41:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2007/09/19/146387.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/146387.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2007/09/19/146387.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/146387.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/146387.html</trackback:ping><description><![CDATA[
		<font color="#ff0000">BUG 修改 :<br /></font>09-20   因为 <em>Oracle </em> 取元数据的字符串需要<font color="#0000ff">大写</font> 至修改并下载更新<br />测试使用表<br /><font color="#ffa500">      ID                           SN   STATIONNAME          SPELL      DEPOTID <br />      -------------- ---- -------------------- ---------- ------- ------------------<br />      08050000390689    3     永安                              ya                ....</font><br /><font color="#ff0000">版本升级 <br /></font><font color="#000000">09-21 <a class="postTitle2" id="viewpost1_TitleUrl" href="/Good-Game/archive/2007/09/21/147110.html">DyanDBUtils 动态面向对象数据库 操作</a></font><br /><br />由于 hibernate 还要table影射成class 这好处和坏处只有我们程序员知道了<br />        只要修改数据库就大量影射附加工作要做 ,有时影射还有BUG弄的我们@#$%!.....(哈hibernate我是小鸟^_^),我----不要----影射 , 没有他们数据库就又回到jdbc.本人比较喜欢偷懒 哈哈 自己来个小框架吧( 就300来行的代码有兴趣的看看哦 )!!! <br /><br />用到技术<br />     BeanUtil , JDBC元数据(在这我可是好好看了下JDBC,其实他是很强的东西,大家应该好好用用^_^) <br />下载<a href="/Files/Good-Game/DBFactory.rar">DBFactory.rar</a><br />DBFactroy<br /><strong><font color="#ffa500">数据是:</font></strong><br /><font color="#ffa500">+----+-------+-------------+------------+<br />| id | title | description | buydate    |<br />+----+-------+-------------+------------+<br />|  6 | tt    | asdgwgw     | 1990-12-02 |<br />+----+-------+-------------+------------+</font><br /><br /><strong><font color="#ffa500">先看看测试吧 <br /></font></strong><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> testNotKonw </span><span style="COLOR: #0000ff">extends</span><span style="COLOR: #000000"> TestCase {<br /><br />    </span><span style="COLOR: #0000ff">protected</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> setUp() </span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception {<br />       <font color="#006400">//运行 sql 可见</font><br />        DBFactory.getTools().setIsShowSql(DBFactory.SHOW);<br />        </span><span style="COLOR: #0000ff">super</span><span style="COLOR: #000000">.setUp();<br />    }<br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> testDelete()</span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception{<br />         <font color="#006400">// select 出来 就的 List 中 DynaBean : id , title .....  类型 , 和值都有了 </font><br />        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(Iterator it </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> DBFactory.getTools().select(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">select * from books</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">).iterator();it.hasNext();){<br />            <font color="#006400">// 那就是delete : 目的是测试前 删除全部数据</font><br />            DBFactory.getTools().delete(it.next());<br />        }<br />    }<br />    <br />      </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> testInsert()</span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception{<br />        <font color="#006400">// insert 要先new出来个 table-&gt;bean  再 添属性 </font> <br />        Object obj </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> DBFactory.getTools().getDynaTableClass(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">books</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">).newInstance();<br />        BeanUtils.setProperty(obj,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">id</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">6</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        BeanUtils.setProperty(obj,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">title</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">tt</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        BeanUtils.setProperty(obj,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">description</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">asdgwgw</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        BeanUtils.setProperty(obj,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">buydate</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Date());<br />       <font color="#006400">//这几是 insert 了 (简单吧)</font><br />        DBFactory.getTools().insert(obj);<br />    }<br />    <br />    </span><span style="COLOR: #008000">// update <br /></span><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> testUpdate()</span><span style="COLOR: #0000ff">throws</span><span style="COLOR: #000000"> Exception{<br />        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(Iterator it </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> DBFactory.getTools().select(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">select * from books</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">).iterator();it.hasNext();){<br />            Object obj </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> it.next();<br />            BeanUtils.setProperty(obj,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">buydate</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Date(</span><span style="COLOR: #000000">90</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">11</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">));<br />            DBFactory.getTools().update(obj);<br />        }<br />    }<br />}<br /></span></div><p><br /><strong><font color="#ffa500">控制台输出</font></strong><br /><font color="#006400">//testDelete </font><br />delete from books where 1=1  and id=6<br /><font color="#008000">//testInsert</font><br />insert into books(id,title,description,buydate) values( 6,'tt','asdgwgw','2007-09-19')<br /><font color="#006400">//testUpdate</font><br />delete from books where 1=1  and id=6<br />insert into books(id,title,description,buydate) values( 6,'tt','asdgwgw','1990-12-02')<br /><br /><strong><font color="#ffa500">代码关键说明:</font></strong><br />关键在BeanUtil 的 DnayBean中 我通过元数据 得到了 这个Bean 属性.属性类型,还有表信息放在 getClass();的字符串中<br />   EG:    table=...;key=..,..,..;columns=...,..,; 后在insert , delet , update就是(先delete后insert^_^)  中 解析得到 动态写sql语句 <br />         更举 DnayBean中属性类型看看 Bean value 是否要加 ' value ' 还是直接 value 到sql 中<br /></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">  BasicDynaClass getDynaTableClass(String table){<br />        Connection conn </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> getConn() ;<br />        List props </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> ArrayList();<br />        DatabaseMetaData dm </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000"> ;<br />        BasicDynaClass dynaClass </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000"> ;<br />        </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"> {    <br />            dm </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> conn.getMetaData();<br />            ResultSet coulumns </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> dm.getColumns(</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">,table,</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">);<br />            </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(coulumns.next()){<br />               <font color="#006400">//元数据中得到 类型做 DynaBean 属性   </font><font color="#006400">coulumns.getInt(</font><font color="#006400"><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><font color="#008000">DATA</font>_<font color="#008000">TYPE</font></span></font><font color="#008000"><span style="COLOR: #000000">"</span><span style="COLOR: #000000">) <font color="#008000"> 是  java.sql.Types.XXXXX </font></span><br /></font>                props.add(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> DynaProperty( coulumns.getString(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">COLUMN_NAME</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">),getStrClass(coulumns.getInt(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">DATA_TYPE</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">))) );<br />            }<br />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> all : table<br />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">delete : column_name column_value<br />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">insert : column_name</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">            StringBuffer sb </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> StringBuffer();<br />            sb.append(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">table=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">).append(table).append(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />            <br />            sb.append(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">keys=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />                ResultSet keys </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> dm.getPrimaryKeys(</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">,table);<br />                </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(keys.next()){<br />                    sb.append( keys.getString(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">column_name</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)).append(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />                }<br />                sb.replace(sb.length()</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,sb.length(),</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />            <br />            sb.append(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">columns=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);    <br />                ResultSet couls </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> dm.getColumns(</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">,</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">,table,</span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">);<br />                </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(couls.next()){<br />                    sb.append( couls.getString(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">column_name</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)).append(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />                }<br />                sb.replace(sb.length()</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,sb.length(),</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />                <br />            <font color="#008000">//为 Class name  &lt;- sb.toString()</font><br />            dynaClass </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> BasicDynaClass(sb.toString() , </span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">, <br />                    (DynaProperty[])props.toArray(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> DynaProperty[]{}) );<br />        } </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (Exception e) {e.printStackTrace();}<br />        </span><span style="COLOR: #0000ff">finally</span><span style="COLOR: #000000">{<br />            </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"> {<br />                conn.close() ;<br />            } </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (SQLException e) {e.printStackTrace();}<br />        }<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> dynaClass ;<br />    }</span></div><p>insert , delete 差不多 就来insert<br /></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000"> insert(Object obj){<br />        String sqlstrat </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">insert into </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />        String sqldo </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> values( </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />        String sqlend </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />        String sql </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">;<br />        </span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000"> od </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000"> ;<br />        <br />        Connection conn </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> getConn() ;<br />        Statement sta </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000"> ;<br />        </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"> {<br />             <font color="#008000">//解析getDynaClass().getName()  得到 table <br /></font>            sqlstrat </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> getTableConfig(obj,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">table</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> ;<br />            <br />             <font color="#008000">//解析getDynaClass().getName()  得到 columns</font><br />            String[] cols </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> getTableConfig(obj,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">columns</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />            </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">cols.length;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">){<br />                sqlstrat </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> cols[i]  </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />                sqldo </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> getSqlAtt(obj,cols[i] )</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />            }<br />            sql </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> sqlstrat.substring(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,sqlstrat.length()</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">sqldo.substring(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">,sqldo.length()</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">sqlend;<br />            sta </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> conn.createStatement();<br />            </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">( sta.executeUpdate(sql)</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">){od </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;};<br />        } </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (Exception e) {e.printStackTrace();}<br />        </span><span style="COLOR: #0000ff">finally</span><span style="COLOR: #000000">{<br />            </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"> {<br />                </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">( isShowSql</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">SHOW ) {System.out.println();System.out.println(sql);}<br />                conn.close();<br />            } </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (SQLException e) {e.printStackTrace();}<br />        }<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> od ;<br />    }<br /></span></div><p><br /><br /><strong><font color="#ffa500">小结:</font></strong><br />当然表连和多表 <strong><font color="#0000ff">查</font></strong> 是没问题的<br />但在多表 delete , update 就还没有完成 (蛮难的 5555  还有 没时间)<br />单表的 delete update ,select,insert 都完成了 我会努力的 <br />大家要是认为还可以 帮忙顶贴 哦 我会都都完善哦<br /></p><img src ="http://www.blogjava.net/Good-Game/aggbug/146387.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2007-09-19 11:41 <a href="http://www.blogjava.net/Good-Game/archive/2007/09/19/146387.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>jdbc 半自动填充 javabean (在大查 hbm 慢速度可以使用) </title><link>http://www.blogjava.net/Good-Game/archive/2007/04/26/113878.html</link><dc:creator>G_G</dc:creator><author>G_G</author><pubDate>Thu, 26 Apr 2007 10:18:00 GMT</pubDate><guid>http://www.blogjava.net/Good-Game/archive/2007/04/26/113878.html</guid><wfw:comment>http://www.blogjava.net/Good-Game/comments/113878.html</wfw:comment><comments>http://www.blogjava.net/Good-Game/archive/2007/04/26/113878.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Good-Game/comments/commentRss/113878.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Good-Game/services/trackbacks/113878.html</trackback:ping><description><![CDATA[代码上了 ----<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">            Collection list </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> ArrayList();<br />            ApplicationsBean applications </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />            ResultSet rs</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />            DBConn db</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />        <br />            </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br />                db</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> DBConn();<br />        <br />          String sql </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">select * from (select rownum row_id,b.* from (select a.* from jcyy.vbasepersonnel a)b) where row_id between </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">sta</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> and </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">end;<br />          <br />          rs</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">db.executeQuery(sql);<br />          ResultSetMetaData md </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> rs.getMetaData() ;<br />          </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> col </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> md.getColumnCount() ; <br />          <br />          </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">[] type </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">[col</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">];<br />          </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> i</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">;i</span><span style="color: rgb(0, 0, 0);">&lt;=</span><span style="color: rgb(0, 0, 0);">col;i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">){<br />              type[i] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> md.getColumnType(i);<br />          }<br />          String[] colNames </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> String[col</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">];<br />          </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> i</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">;i</span><span style="color: rgb(0, 0, 0);">&lt;=</span><span style="color: rgb(0, 0, 0);">col;i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">){<br />              colNames[i</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> md.getColumnName(i).trim();<br />          }<br />          <br />          Hashtable map </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Hashtable();  <br />          Method[] mes </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">  Vbasepersonnel.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">.getMethods() ;<br />              </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> i</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">; i</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">mes.length;i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">){<br />                String setName </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> mes[i].getName().trim();    <br />                </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(setName.indexOf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">set</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">){<br />                    String name </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> setName.substring(</span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">,setName.length()).toUpperCase();<br />                    map.put(name,mes[i]);<br />                }<br />            }<br />            <br />              <br /><br />                  </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);"> (rs.next()) {<br />                      Vbasepersonnel vb </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Vbasepersonnel();<br />                      <br />                      </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> i</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">;i</span><span style="color: rgb(0, 0, 0);">&lt;=</span><span style="color: rgb(0, 0, 0);">col;i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">){<br />                          <br />                          </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(colNames[i] </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 0, 255);">continue</span><span style="color: rgb(0, 0, 0);"> ;</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">个别的可 另拿出来 if colNames == NN  -&gt;  rs.getXXXX()</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                          <br />                          Method me </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (Method)map.get( colNames[i] );<br />                          </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(me </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">){<br />                              </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);">{<br />                              </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(type[i]</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">java.sql.Types.DATE)    me.invoke(vb,</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Object[]{rs.getDate(colNames[i])});<br />                              </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(type[i]</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">java.sql.Types.INTEGER)    me.invoke(vb,</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Object[]{</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Integer(rs.getInt(colNames[i]))});<br />                              </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">if(type[i]==java.sql.Types.BIGINT)    me.invoke(vb,new Object[]{rs.getBigDecimal(colNames[i])});</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">                              </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(type[i]</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">java.sql.Types.DOUBLE)    me.invoke(vb,</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Object[]{</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Double(rs.getDouble(colNames[i]))});<br />                              </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(type[i]</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">java.sql.Types.FLOAT)    me.invoke(vb,</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Object[]{</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Float(rs.getFloat(colNames[i]))});<br />                              </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(type[i]</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">java.sql.Types.BOOLEAN)    me.invoke(vb,</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Object[]{</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Boolean(rs.getBoolean(colNames[i]))});<br />                              </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(type[i]</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">java.sql.Types.LONGVARBINARY)    me.invoke(vb,</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Object[]{</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Long(rs.getLong(colNames[i]))});<br />                              </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(type[i]</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">java.sql.Types.BOOLEAN)     me.invoke(vb,</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Object[]{</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Boolean(rs.getBoolean(colNames[i]))});<br />                              <br />                              </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);">    me.invoke(vb,</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Object[]{rs.getObject(colNames[i])});<br />                              }</span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);">(Exception ex){<br />                                  System.out.println(colNames[i]</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">XX</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">type[i]);<br />                                  colNames[i] </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"> ;<br />                              }<br />                          }<br />                      }<br />                      <br />                      list.add(vb);<br />                }<br /><br /></span></div><br /><br /><img src ="http://www.blogjava.net/Good-Game/aggbug/113878.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Good-Game/" target="_blank">G_G</a> 2007-04-26 18:18 <a href="http://www.blogjava.net/Good-Game/archive/2007/04/26/113878.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>