﻿<?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-cuiyi's blog（崔毅 crazycy）-随笔分类-DBMS</title><link>http://blogjava.net/crazycy/category/8596.html</link><description>记录点滴 鉴往事之得失 以资于发展 </description><language>zh-cn</language><lastBuildDate>Sat, 26 Apr 2008 07:03:17 GMT</lastBuildDate><pubDate>Sat, 26 Apr 2008 07:03:17 GMT</pubDate><ttl>60</ttl><item><title>非常有意思的sql排错</title><link>http://www.blogjava.net/crazycy/archive/2008/04/08/191534.html</link><dc:creator>crazycy</dc:creator><author>crazycy</author><pubDate>Tue, 08 Apr 2008 10:30:00 GMT</pubDate><guid>http://www.blogjava.net/crazycy/archive/2008/04/08/191534.html</guid><wfw:comment>http://www.blogjava.net/crazycy/comments/191534.html</wfw:comment><comments>http://www.blogjava.net/crazycy/archive/2008/04/08/191534.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/crazycy/comments/commentRss/191534.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/crazycy/services/trackbacks/191534.html</trackback:ping><description><![CDATA[<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">1)&nbsp; 你看出区别在哪里了么？ 结果会一样么？<br />
SELECT<br />
(select&nbsp;first&nbsp;</span><span style="color: #000000;">1</span><span style="color: #000000;">&nbsp;longname&nbsp;from&nbsp;ivctrallocpurch&nbsp;a&nbsp;join&nbsp;jcivloc&nbsp;l&nbsp; on&nbsp;a.ivlocid</span><span style="color: #000000;">=</span><span style="color: #000000;">l.ivlocid&nbsp;and&nbsp;a.ctrid</span><span style="color: #000000;">=</span><span style="color: #000000;">A.ctrid)&nbsp;as&nbsp;mill<br />
FROM&nbsp;CTR&nbsp;A<br />
JOIN&nbsp;CTRSMRY&nbsp;CS&nbsp;ON&nbsp;(A.CTRID</span><span style="color: #000000;">=</span><span style="color: #000000;">CS.CTRID)<br />
WHERE&nbsp;A.CTRID</span><span style="color: #000000;">=3161</span><span style="color: #000000;"><br />
</span></div>
和<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">SELECT<br />
(select&nbsp;first&nbsp;</span><span style="color: #000000;">1</span><span style="color: #000000;">&nbsp;longname&nbsp;from&nbsp;ivctrallocpurch&nbsp;a&nbsp;join&nbsp;jcivloc&nbsp;l&nbsp;&nbsp;on&nbsp;a.ivlocid</span><span style="color: #000000;">=</span><span style="color: #000000;">l.ivlocid&nbsp;and&nbsp;a.ctrid</span><span style="color: #000000;">=</span><span style="color: #000000;">3161</span><span style="color: #000000;">)&nbsp;as&nbsp;mill<br />
FROM&nbsp;CTR&nbsp;A<br />
JOIN&nbsp;CTRSMRY&nbsp;CS&nbsp;ON&nbsp;(A.CTRID</span><span style="color: #000000;">=</span><span style="color: #000000;">CS.CTRID)<br />
WHERE&nbsp;A.CTRID</span><span style="color: #000000;">=</span><span style="color: #000000;">3161</span></div>
结果为什么不一样呢？<br />
<br />
<br />
2） Integer overflow. The result of an integer operation caused the most significant bit of the result to carry.<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">select&nbsp;sum(rcpt.artothome&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;"> rate</span><span style="color: #000000;">)&nbsp;as amt<br />
from cashreceipt rcpt<br />
join homerate rate on rcpt.currencyid=rate.currencyid</span></div>
分析：<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">artothome&nbsp;@&nbsp;arheader&nbsp;&nbsp;is&nbsp;:&nbsp;numeric(</span><span style="color: #000000;">18</span><span style="color: #000000;">,</span><span style="color: #000000;">4</span><span style="color: #000000;">)<br />
rate&nbsp;@&nbsp;..&nbsp;&nbsp;is&nbsp;:&nbsp;numeric(</span><span style="color: #000000;">10</span><span style="color: #000000;">,</span><span style="color: #000000;">10</span><span style="color: #000000;">)</span></div>
<span style="color: #000000;">改进1 (not work)<br />
</span>
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">select&nbsp;sum(cast(rcpt.artothome&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">&nbsp;rate&nbsp;as&nbsp;numeric(</span><span style="color: #000000;">18</span><span style="color: #000000;">,</span><span style="color: #000000;">4</span><span style="color: #000000;">)))&nbsp;as&nbsp;amt<br />
from&nbsp;cashreceipt&nbsp;rcpt<br />
join&nbsp;homerate&nbsp;rate&nbsp;on&nbsp;rcpt.currencyid</span><span style="color: #000000;">=</span><span style="color: #000000;">rate.currencyid</span></div>
<span style="color: #000000;">改进2 (works)<br />
</span>
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">select&nbsp;sum(cast(cast(rcpt.artothome as numeric(18,4)) </span><span style="color: #000000;">*</span><span style="color: #000000;"> cast(rate as numeric(18,4)) as&nbsp;numeric(</span><span style="color: #000000;">18</span><span style="color: #000000;">,</span><span style="color: #000000;">4</span><span style="color: #000000;">)))&nbsp;as&nbsp;amt<br />
from&nbsp;cashreceipt&nbsp;rcpt<br />
join&nbsp;homerate&nbsp;rate&nbsp;on&nbsp;rcpt.currencyid</span><span style="color: #000000;">=</span><span style="color: #000000;">rate.currencyid</span></div>
reason, forward from http://www.firebirdfaq.org/faq207/<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">Integer&nbsp;overflow.&nbsp;The&nbsp;result&nbsp;of&nbsp;an&nbsp;integer&nbsp;operation&nbsp;caused&nbsp;the&nbsp;most&nbsp;significant&nbsp;bit&nbsp;of&nbsp;the&nbsp;result&nbsp;to&nbsp;carry.<br />
</span><span style="color: #000000;"><br />
Short&nbsp;explanation:<br />
If&nbsp;you&nbsp;use&nbsp;fixed&nbsp;precision&nbsp;datatypes&nbsp;(smallint,&nbsp;integer,&nbsp;bigint,&nbsp;decimal&nbsp;and&nbsp;numeric),&nbsp;it&nbsp;is&nbsp;possible&nbsp;that&nbsp;the&nbsp;result&nbsp;of&nbsp;calculation&nbsp;doesn</span><span style="color: #000000;">'</span><span style="color: #000000;">t&nbsp;fit&nbsp;the&nbsp;datatype.&nbsp;Try&nbsp;casting&nbsp;the&nbsp;values&nbsp;in&nbsp;complex&nbsp;expressions&nbsp;as&nbsp;double&nbsp;precision&nbsp;and&nbsp;see&nbsp;whether&nbsp;the&nbsp;error&nbsp;goes&nbsp;away.&nbsp;If&nbsp;it&nbsp;works&nbsp;and&nbsp;you&nbsp;don</span><span style="color: #000000;">'</span><span style="color: #000000;">t&nbsp;care&nbsp;about&nbsp;being&nbsp;too&nbsp;precise,&nbsp;you&nbsp;can&nbsp;leave&nbsp;it&nbsp;at&nbsp;that.&nbsp;Otherwise&nbsp;you&nbsp;need&nbsp;to&nbsp;check&nbsp;every&nbsp;operation&nbsp;and&nbsp;calculate&nbsp;the&nbsp;result.<br />
<br />
Details:<br />
Here</span><span style="color: #000000;">'</span><span style="color: #000000;">s&nbsp;an&nbsp;example:&nbsp;if&nbsp;you&nbsp;multiply&nbsp;9.12&nbsp;with&nbsp;8.11&nbsp;(both&nbsp;numeric(18,2))&nbsp;you&nbsp;would&nbsp;get&nbsp;73.9632.&nbsp;If&nbsp;Firebird&nbsp;would&nbsp;store&nbsp;that&nbsp;into&nbsp;numeric(18,2)&nbsp;datatype,&nbsp;we&nbsp;would&nbsp;lose&nbsp;0.0032.&nbsp;Doesn</span><span style="color: #000000;">'</span><span style="color: #000000;">t&nbsp;look&nbsp;much,&nbsp;but&nbsp;when&nbsp;you&nbsp;have&nbsp;complex&nbsp;calculations,&nbsp;you&nbsp;can&nbsp;easily&nbsp;loose&nbsp;thousands&nbsp;(dollars&nbsp;or&nbsp;euros).&nbsp;Therefore,&nbsp;the&nbsp;result&nbsp;is&nbsp;stored&nbsp;in&nbsp;numeric(</span><span style="color: #000000;">18</span><span style="color: #000000;">,</span><span style="color: #000000;">4</span><span style="color: #000000;">).<br />
<br />
Problems&nbsp;are&nbsp;rarely&nbsp;seen&nbsp;with&nbsp;such&nbsp;low&nbsp;precision&nbsp;as&nbsp;</span><span style="color: #000000;">2</span><span style="color: #000000;">.&nbsp;Let</span><span style="color: #000000;">'</span><span style="color: #000000;">s&nbsp;use&nbsp;some&nbsp;bigger&nbsp;precision.&nbsp;For&nbsp;example,&nbsp;numeric(18,6)&nbsp;times&nbsp;numeric(18,6)&nbsp;yields&nbsp;numeric(18,12)&nbsp;result,&nbsp;meaning&nbsp;that&nbsp;maximal&nbsp;value&nbsp;it&nbsp;can&nbsp;store&nbsp;is&nbsp;9223372.036854775807.&nbsp;If&nbsp;(for&nbsp;example)&nbsp;you&nbsp;wish&nbsp;to&nbsp;keep&nbsp;only&nbsp;6&nbsp;digits&nbsp;of&nbsp;precision,&nbsp;you&nbsp;could&nbsp;use&nbsp;something&nbsp;like:</span><span style="color: #000000;"><br />
</span><span style="color: #000000;"><br />
cast(value1&nbsp;as&nbsp;numeric(</span><span style="color: #000000;">18</span><span style="color: #000000;">,</span><span style="color: #000000;">3</span><span style="color: #000000;">))&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">&nbsp;cast(value2&nbsp;as&nbsp;numeric(</span><span style="color: #000000;">18</span><span style="color: #000000;">,</span><span style="color: #000000;">3</span><span style="color: #000000;">))<br />
<br />
which&nbsp;would&nbsp;yield&nbsp;numeric(</span><span style="color: #000000;">18</span><span style="color: #000000;">,</span><span style="color: #000000;">6</span><span style="color: #000000;">)&nbsp;result,&nbsp;but&nbsp;it&nbsp;is&nbsp;quite&nbsp;possible&nbsp;that&nbsp;you&nbsp;would&nbsp;get&nbsp;more&nbsp;accurate&nbsp;result&nbsp;by&nbsp;casting&nbsp;to&nbsp;</span><span style="color: #0000ff;">double</span><span style="color: #000000;">:<br />
<br />
cast(cast(value1&nbsp;as&nbsp;</span><span style="color: #0000ff;">double</span><span style="color: #000000;">&nbsp;precision)&nbsp;</span><span style="color: #000000;">*</span><span style="color: #000000;">&nbsp;cast(value2&nbsp;as&nbsp;</span><span style="color: #0000ff;">double</span><span style="color: #000000;">&nbsp;precision)&nbsp;as&nbsp;numeric(</span><span style="color: #000000;">18</span><span style="color: #000000;">,</span><span style="color: #000000;">6</span><span style="color: #000000;">))<br />
<br />
Also,&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;you&nbsp;have&nbsp;mixed&nbsp;multiplications&nbsp;and&nbsp;divisions&nbsp;it&nbsp;helps&nbsp;to&nbsp;change&nbsp;the&nbsp;order&nbsp;of&nbsp;operations,&nbsp;so&nbsp;that&nbsp;the&nbsp;overflow&nbsp;doesn</span><span style="color: #000000;">'</span><span style="color: #000000;">t&nbsp;happen. <br />
</span></div>
<br />
<br />
<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">String sql = "select mbrid from jcmbr where reference4=?";<br />
假如没有记录<br />
DynaBean&nbsp;aBean&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;CxcDataModule.getInstance().getRow(sql,&nbsp;</span><span style="color: #0000ff;">new</span><span style="color: #000000;">&nbsp;Object[]{</span><span style="color: #000000;">reference4</span><span style="color: #000000;">});<br />
如果直接用aBean.get("</span><span style="color: #000000;">reference4"</span><span style="color: #000000;">) 出错；<br />
错误的原因是</span><span style="color: #000000;">aBean&nbsp; </span><span style="color: #000000;">为null</span><br />
<span style="color: #000000;"><br />
Object&nbsp;obj&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;"> {spring jdbctemplate}.queryForObject(sql,&nbsp;</span><span style="color: #0000ff;">new</span><span style="color: #000000;">&nbsp;Object[]{</span><span style="color: #000000;">reference4</span><span style="color: #000000;">},&nbsp;Integer.</span><span style="color: #0000ff;">class</span><span style="color: #000000;">);<br />
</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(obj&nbsp;</span><span style="color: #0000ff;">instanceof</span><span style="color: #000000;">&nbsp;Integer)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(</span><span style="color: #000000;">"</span><span style="color: #000000;">(Integer)obj&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">+</span><span style="color: #000000;">&nbsp;(Integer)obj);<br />
</span><span style="color: #0000ff;">else</span><span style="color: #000000;">&nbsp;</span><span style="color: #0000ff;">if</span><span style="color: #000000;">&nbsp;(obj&nbsp;</span><span style="color: #0000ff;">instanceof</span><span style="color: #000000;">&nbsp;Map)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</span><span style="color: #000000;">"</span><span style="color: #000000;">(Integer)obj&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">+</span><span style="color: #000000;">&nbsp;((Map)obj).get(</span><span style="color: #000000;">"REFERENCE4</span><span style="color: #000000;">"</span><span style="color: #000000;">));<br />
真是的流程是 if 分支<br />
如果有数据，这是对的<br />
如果没有数据，直接出错，因为有个假定有Integer值存在<br />
<br />
</span><span style="color: #0000ff;">int</span><span style="color: #000000;">&nbsp;value&nbsp;</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;JcDataModuleUtils.getJdbcTemplate().queryForInt(sql,&nbsp;</span><span style="color: #0000ff;">new</span><span style="color: #000000;">&nbsp;Object[]{</span><span style="color: #000000;">reference4</span><span style="color: #000000;">});</span><span style="color: #000000;"><br />
出错原因是假定一定会有一个int值返回</span><br />
<span style="color: #000000;">15:09:00,438 ERROR [STDERR] Caused by: org.springframework.dao.IncorrectResultSizeDataAccessException: Incorrect result size:<br />
&nbsp;expected 1, actual 0<br />
15:09:00,438 ERROR [STDERR]&nbsp;&nbsp;&nbsp;&nbsp; at org.springframework.dao.support.DataAccessUtils.requiredUniqueResult(DataAccessUtils.java:<br />
66)<br />
15:09:00,469 ERROR [STDERR]&nbsp;&nbsp;&nbsp;&nbsp; at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:620)<br />
15:09:00,469 ERROR [STDERR]&nbsp;&nbsp;&nbsp;&nbsp; at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:629)<br />
15:09:00,469 ERROR [STDERR]&nbsp;&nbsp;&nbsp;&nbsp; at org.springframework.jdbc.core.JdbcTemplate.queryForInt(JdbcTemplate.java:656)<br />
</span></div>
<br />
<br />
<br />
<br />
<img src ="http://www.blogjava.net/crazycy/aggbug/191534.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/crazycy/" target="_blank">crazycy</a> 2008-04-08 18:30 <a href="http://www.blogjava.net/crazycy/archive/2008/04/08/191534.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql乱码编码的解决之道(不含分析) </title><link>http://www.blogjava.net/crazycy/archive/2007/12/23/169827.html</link><dc:creator>crazycy</dc:creator><author>crazycy</author><pubDate>Sun, 23 Dec 2007 10:07:00 GMT</pubDate><guid>http://www.blogjava.net/crazycy/archive/2007/12/23/169827.html</guid><wfw:comment>http://www.blogjava.net/crazycy/comments/169827.html</wfw:comment><comments>http://www.blogjava.net/crazycy/archive/2007/12/23/169827.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/crazycy/comments/commentRss/169827.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/crazycy/services/trackbacks/169827.html</trackback:ping><description><![CDATA[mysql的中文乱码,大多是因为mysql的编码选择造成的。<br />
以mysql的两个相同结构的表间进行数据迁移为例，做了三种情况的测试，并提出解决乱码的解决方法如下:<br />
<br />
<p class="MsoNormal">Migration between MySQLs</p>
<p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span><span>1)<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><!--[endif]-->Migration between character set : utf8</p>
<p class="MsoNormal" style="margin-left: 0.5in;">Amend my.ini (2 positions)</p>
<p class="MsoNormal" style="margin-left: 0.5in;">default-character-set=latin1</p>
<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: Wingdings;"><span>=&gt;<br />
</span></span></p>
<p class="MsoNormal" style="margin-left: 0.5in;">default-character-set=utf8</p>
<p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span><span>2)<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><!--[endif]-->Migration between character set : origin is utf8 ==&gt;<span style="font-family: Wingdings;"></span>
the
destination is latin1</p>
<p class="MsoNormal" style="margin-left: 0.5in;">Alter destination:</p>
<ul>
    <li><!--[if !supportLists]--><span style="font-family: Wingdings;"><span><span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
    </span></span></span><!--[endif]-->alter database [db_name] default character set utf8;<span style="font-family: Wingdings;"></span></li>
    <li><span style="font-family: Wingdings;"><span><span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">
    </span></span></span><!--[endif]-->alter table [table_name] default character set
    utf8;<span style="font-family: Wingdings;"></span></li>
    <li><span style="font-family: Wingdings;"><span><span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;</span></span></span>alter table [table_name] change [field_name]
    [field_name] [filed type] varchar(45) character set utf8;</li>
    <ul>
        <li>example</li>
    </ul>
</ul>
<p class="MsoNormal" style="margin-left: 1in;">users(id, user_name)</p>
<p class="MsoNormal" style="margin-left: 1in;">alter table users <span>&nbsp;</span>change user_name user_name varchar(45)
character set utf8;</p>
<p class="MsoNormal" style="margin-left: 1in;"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><!--[if !supportLists]--><span><span>3)<span style="font-family: &quot;Times New Roman&quot;; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span></span></span><!--[endif]-->Migration between character set : origin is
latin1 ==&gt;<span style="font-family: Wingdings;"></span>
the destination is utf8</p>
<p class="MsoNormal" style="margin-left: 0.5in;">If the origin is latin1, cannot
insert Chinese Character. </p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<br />
<img src ="http://www.blogjava.net/crazycy/aggbug/169827.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/crazycy/" target="_blank">crazycy</a> 2007-12-23 18:07 <a href="http://www.blogjava.net/crazycy/archive/2007/12/23/169827.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>firebird技巧和错误分析与总结</title><link>http://www.blogjava.net/crazycy/archive/2007/11/03/157940.html</link><dc:creator>crazycy</dc:creator><author>crazycy</author><pubDate>Sat, 03 Nov 2007 09:06:00 GMT</pubDate><guid>http://www.blogjava.net/crazycy/archive/2007/11/03/157940.html</guid><wfw:comment>http://www.blogjava.net/crazycy/comments/157940.html</wfw:comment><comments>http://www.blogjava.net/crazycy/archive/2007/11/03/157940.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/crazycy/comments/commentRss/157940.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/crazycy/services/trackbacks/157940.html</trackback:ping><description><![CDATA[1）<br />
<strong>Cmd </strong>&gt;&gt; isql localhost/3050:path/cxcdata.fdb -user sysdba -pass masterkey<br />
<strong>Error </strong>&gt;&gt; <br />
Statement failed, SQLCODE = -902<br />
<br />
Unable to complete network request to host "localhost".<br />
-Failed to establish a connection.<br />
-No connection could be made because the target machine actively refused it.<br />
<br />
Use CONNECT or CREATE DATABASE to specify a database<br />
<strong>Solution</strong>&gt;&gt;<br />
check whether service or application of firebird start or not<br />
<br />
2) <br />
<strong>Scenario</strong>&gt;&gt;Using EMS Data Export for Interbase/Firebird<br />
<strong>Error</strong>&gt;&gt; <br />
<img src="file:///C:/Users/cuiyi/AppData/Local/Temp/moz-screenshot.jpg" alt="" /><img src="file:///C:/Users/cuiyi/AppData/Local/Temp/moz-screenshot-2.jpg" alt="" /><img alt="" src="http://www.blogjava.net/images/blogjava_net/crazycy/firebird/gds_error.jpg" height="182" width="482" /><br />
<strong>Solution</strong>&gt;&gt;windows\system32\drivers\etc目录下的services文件中添加<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gds_db 3050/tcp<br />
<br />
3) windows下firebird对db路径要求：与firebird直接交互的fdb文件必须增加前缀：localhost/3050:[driver]/{[path]/}[.fdb file]<br />
&nbsp;&nbsp;&nbsp; 无论是isql 还是 gbak<br />
&nbsp;&nbsp;&nbsp; 比如 test.fdb 在d:\dbfile\firebird\test.fdb<br />
&nbsp;&nbsp;&nbsp; connect db: cmd&gt;&gt; isql localhost/3050:d:/dbfile/firebird/test.fdb -user [username] -pass [userpass]<br />
&nbsp;&nbsp;&nbsp; backup db: cmd&gt;&gt; gbak -B localhost/3050:d:/dbfile/firebird/test.fdb test.fbk -user [username] -pass [userpass]<br />
&nbsp;&nbsp;&nbsp; restore db: cmd&gt;&gt; gbak -C test.fbk localhost/3050:d:/dbfile/firebird/test.fdb -user [username] -pass [userpass]<br />
&nbsp;&nbsp;&nbsp; NOTE: only the fdb file should add the localhost constraint<br />
&nbsp;&nbsp;&nbsp; <img alt="" src="http://www.blogjava.net/images/blogjava_net/crazycy/firebird/isql.jpg" height="150" width="593" /><br />
&nbsp;&nbsp;&nbsp; <br />
4) db installed in d:/dbfile/firebird/test.fdb<br />
&nbsp;&nbsp;&nbsp; connect way 1&gt;&gt;&nbsp; isql localhost/3050:d:/dbfile/firebird/test.fdb -user [username] -pass [userpass]<br />
&nbsp;&nbsp;&nbsp; connect way 2&gt;&gt; isql localhost/3050:db -user [username] -pass [userpass] <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add this line : db = d:/dbfile/firebird/test.fdb&nbsp; in aliases.conf, no need restart firebird service<br />
<br />
5）about amention of db's path for different customer<br />
we offten configure db path in apps using jdbc:firebird:localhost:[path]/[db file]&nbsp;&nbsp; like jdbc:firebird:localhost: d:/dbfile/firebird/test.fdb<br />
As you know, in most time we install db in different folder for different customers; so we must keep re-compile apps or modify war/jar/ear every time.<br />
<br />
So basis on this issue,&nbsp; we can change to configure db using firebird self file called <span style="background-color: yellow;">aliases.conf</span><br />
like this form (basis my local configuration):<br />
<span style="background-color: #98c5ff;">test.fdb = d:/dbfile/firebird/test.fdb</span><br />
<br />
so now using this form jdbc:firebird:localhost:test.fdb&nbsp; in&nbsp; apps <br />
I tried both windows and linux, it works;<br />
<br />
<img src ="http://www.blogjava.net/crazycy/aggbug/157940.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/crazycy/" target="_blank">crazycy</a> 2007-11-03 17:06 <a href="http://www.blogjava.net/crazycy/archive/2007/11/03/157940.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>得到PrepareStatement最终执行的sql语句的方法</title><link>http://www.blogjava.net/crazycy/archive/2006/07/22/59581.html</link><dc:creator>crazycy</dc:creator><author>crazycy</author><pubDate>Sat, 22 Jul 2006 13:53:00 GMT</pubDate><guid>http://www.blogjava.net/crazycy/archive/2006/07/22/59581.html</guid><wfw:comment>http://www.blogjava.net/crazycy/comments/59581.html</wfw:comment><comments>http://www.blogjava.net/crazycy/archive/2006/07/22/59581.html#Feedback</comments><slash:comments>11</slash:comments><wfw:commentRss>http://www.blogjava.net/crazycy/comments/commentRss/59581.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/crazycy/services/trackbacks/59581.html</trackback:ping><description><![CDATA[在CSDN的JAVA基础版,常常有人问及如何得到PreparedStatement最终执行的SQL语句;或者如何在控制台输出占位符的真实值.....<br /><br />原因就是PreparedStatement执行的sql语句有大量的占位符?....<br /><br />问题诸如JDBC中:<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);">如何得到 conn.prepareStatement 最终执行的sql语句。<br />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);">update table1 set a=?,b=?</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br />stmt </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> con.prepareStatement(sql);<br />stmt.setObjec t(</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);">a</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />stmt.setObjec t(</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">b</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /><br />希望可以通过stmt或者conn 得到：<br />update table1 set a</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">a</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">,b</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">'</span><span style="color: rgb(0, 0, 0);">b</span><span style="color: rgb(0, 0, 0);">'</span></div><br />亦或Hibernate中<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);">如我执行：find(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">select * from t_table where id = ?</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);"> Integer(</span><span style="color: rgb(0, 0, 0);">5</span><span style="color: rgb(0, 0, 0);">));<br />在控制台显示SQL时只显示：select </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);"> from t_table where id </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);"><br />如何才能做到将控制台显示的占位符用其真实的值来替换？<br />即控制台输出时显示：select </span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);"> from t_table where id </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">5</span><span style="color: rgb(0, 0, 0);"><br /></span></div><br />无它，无论JDBC还是Hiberante都不提供默认解决方案，但是参数是设置进去的，我们在设置的过程中可以有充分的理由来截取并获得自己想要的东西，类似于AOP理论。<br /><br />共享我在工程中的使用方法：<br />插入操作：<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, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * 执行插入数据库的语句<br />     * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> sql<br />     * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> params<br />     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"> 返回生成的主键<br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</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);"> executeInsert(String sql, Object[] params) {<br />        Connection conn </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 />        PreparedStatement pstmt </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, 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, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">1 获得连接</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            conn </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> MyDBConnection.getInstance().getConnection();<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">2 设置提交方式为程序控制</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            conn.setAutoCommit(</span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">);<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">3 获得语句对象</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            pstmt </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">4 设置SQL语句的参数</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);"> (</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> params </span><span style="color: rgb(0, 0, 0);">&amp;&amp;</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);"> </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> params.length) {<br />                setParams(pstmt, params);<br />            }<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">5 打印SQL语句</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);"> (MyDBConstants.showSQL) {<br />                getPreparedSQL(sql, params);<br />            }<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">6 执行语句</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            pstmt.executeUpdate();<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">7 程序提交</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            conn.commit();<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">8 返回生成的主键</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            rs </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> pstmt.getGeneratedKeys();<br />            </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> generatedKey </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 />            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (rs.next()) {<br />                generatedKey </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> rs.getInt(</span><span style="color: rgb(0, 0, 0);">1</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);"> (</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> generatedKey)<br />                </span><span style="color: rgb(0, 0, 255);">throw</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);"> MySQLException(</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);">);<br />            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> generatedKey;<br />        } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (SQLException e) {<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">回滚</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            MyDBUtil.rollBack(conn);<br />            </span><span style="color: rgb(0, 0, 255);">throw</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);"> MySQLException(e);<br />        } </span><span style="color: rgb(0, 0, 255);">finally</span><span style="color: rgb(0, 0, 0);"> {<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">关闭打开的操作</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            MyDBUtil.close(conn, pstmt, rs);<br />        }<br />    }</span></div><br /><br />更新查找操作：<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, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * 执行更新或者删除数据库的语句<br />     * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> sql<br />     * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> params<br />     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"> 返回执行成功与否<br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">boolean</span><span style="color: rgb(0, 0, 0);"> executeUpdateDel(String sql, Object[] params) {<br />        </span><span style="color: rgb(0, 0, 255);">boolean</span><span style="color: rgb(0, 0, 0);"> isSuccess </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">;<br />        Connection conn </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 />        PreparedStatement pstmt </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, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">1 获得连接</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            conn </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> MyDBConnection.getInstance().getConnection();<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">2 设置提交方式为程序控制</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            conn.setAutoCommit(</span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">);<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">3 获得语句对象</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            pstmt </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> conn.prepareStatement(sql);<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">4 设置SQL语句的参数</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);"> (</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> params </span><span style="color: rgb(0, 0, 0);">&amp;&amp;</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);"> </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> params.length) {<br />                setParams(pstmt, params);<br />            }<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">5 打印SQL语句</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);"> (MyDBConstants.showSQL) {<br />                getPreparedSQL(sql, params);<br />            }<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">6 执行语句</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            pstmt.executeUpdate();<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">7 程序提交</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            conn.commit();<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">8 设置语句执行的标记</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            isSuccess </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">;<br />        } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (SQLException e) {<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">回滚</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            MyDBUtil.rollBack(conn);<br />            </span><span style="color: rgb(0, 0, 255);">throw</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);"> MySQLException(e);<br />        } </span><span style="color: rgb(0, 0, 255);">finally</span><span style="color: rgb(0, 0, 0);"> {<br />            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">关闭打开的操作</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            MyDBUtil.close(conn, pstmt);<br />        }<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> isSuccess;<br />    }</span></div><br />执行查询<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, 128, 128);"> 1</span> <span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 128, 0);">     * 执行查询数据库的语句;</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 128, 0);">     *<br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 128, 0);">     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 128, 0);">     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> Object executeQuery(String sql, Object[] params) {<br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);">        Connection conn </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, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);">        PreparedStatement pstmt </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, 128, 128);">15</span> <span style="color: rgb(0, 0, 0);">        ResultSet rs </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, 128, 128);">16</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br /></span><span style="color: rgb(0, 128, 128);">17</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">1 获得连接</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">18</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">            conn </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> MyDBConnection.getInstance().getConnection();<br /></span><span style="color: rgb(0, 128, 128);">19</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">2 设置提交方式为程序控制</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">20</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">            conn.setAutoCommit(</span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">21</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">3 获得语句对象</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">22</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">            pstmt </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);<br /></span><span style="color: rgb(0, 128, 128);">23</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">4 设置SQL语句的参数</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">24</span> <span style="color: rgb(0, 128, 0);"></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);"> (</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> params </span><span style="color: rgb(0, 0, 0);">&amp;&amp;</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);"> </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> params.length) {<br /></span><span style="color: rgb(0, 128, 128);">25</span> <span style="color: rgb(0, 0, 0);">                setParams(pstmt, params);<br /></span><span style="color: rgb(0, 128, 128);">26</span> <span style="color: rgb(0, 0, 0);">            }<br /></span><span style="color: rgb(0, 128, 128);">27</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">5 打印SQL语句</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">28</span> <span style="color: rgb(0, 128, 0);"></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);"> (MyDBConstants.showSQL) {<br /></span><span style="color: rgb(0, 128, 128);">29</span> <span style="color: rgb(0, 0, 0);">                getPreparedSQL(sql, params);<br /></span><span style="color: rgb(0, 128, 128);">30</span> <span style="color: rgb(0, 0, 0);">            }<br /></span><span style="color: rgb(0, 128, 128);">31</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">6 执行语句</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">32</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">            rs </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> pstmt.executeQuery();<br /></span><span style="color: rgb(0, 128, 128);">33</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">34</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">9 程序提交</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">35</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">            conn.commit();<br /></span><span style="color: rgb(0, 128, 128);">36</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">37</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">10 获得记录</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">38</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">            Object vo </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);"> Object();<br /></span><span style="color: rgb(0, 128, 128);">39</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);"> (</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> rs </span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 0);"> rs.next()) {<br /></span><span style="color: rgb(0, 128, 128);">40</span> <span style="color: rgb(0, 0, 0);">                vo </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> rs2vo(rs);<br /></span><span style="color: rgb(0, 128, 128);">41</span> <span style="color: rgb(0, 0, 0);">            }<br /></span><span style="color: rgb(0, 128, 128);">42</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">            return results;</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">43</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> vo;<br /></span><span style="color: rgb(0, 128, 128);">44</span> <span style="color: rgb(0, 0, 0);">        } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (SQLException e) {<br /></span><span style="color: rgb(0, 128, 128);">45</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">回滚</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">46</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">            MyDBUtil.rollBack(conn);<br /></span><span style="color: rgb(0, 128, 128);">47</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">throw</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);"> MySQLException(e);<br /></span><span style="color: rgb(0, 128, 128);">48</span> <span style="color: rgb(0, 0, 0);">        } </span><span style="color: rgb(0, 0, 255);">finally</span><span style="color: rgb(0, 0, 0);"> {<br /></span><span style="color: rgb(0, 128, 128);">49</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">关闭打开的操作</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">50</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">            MyDBUtil.close(conn, pstmt, rs);<br /></span><span style="color: rgb(0, 128, 128);">51</span> <span style="color: rgb(0, 0, 0);">        }<br /></span><span style="color: rgb(0, 128, 128);">52</span> <span style="color: rgb(0, 0, 0);">    }</span></div><br />看到<span style="color: rgb(0, 0, 0);">getPreparedSQL(sql, params)了么？ 这个地方就是要实现我们预期效果的地方：<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%;"><img id="Code_Closed_Image_215212" onclick="this.style.display='none'; Code_Closed_Text_215212.style.display='none'; Code_Open_Image_215212.style.display='inline'; Code_Open_Text_215212.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" height="16" width="11" /><img id="Code_Open_Image_215212" style="display: none;" onclick="this.style.display='none'; Code_Open_Text_215212.style.display='none'; Code_Closed_Image_215212.style.display='inline'; Code_Closed_Text_215212.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" height="16" width="11" /><span id="Code_Closed_Text_215212" style="border: 1px solid rgb(128, 128, 128); background-color: rgb(255, 255, 255);">得到PrepareStatement最终执行的sql语句的方法</span><span id="Code_Open_Text_215212" style="display: none;"><br /><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 128, 0);">     * 获得PreparedStatement向数据库提交的SQL语句<br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 128, 0);">     * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> sql<br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 128, 0);">     * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> params<br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 128, 0);">     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 128, 0);">     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> String getPreparedSQL(String sql, Object[] params) {<br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">1 如果没有参数，说明是不是动态SQL语句</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 128, 0);"></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);"> paramNum </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 /></span><span style="color: rgb(0, 128, 128);">10</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);"> (</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> params)  paramNum </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> params.length;<br /></span><span style="color: rgb(0, 128, 128);">11</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);"> (</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);">&gt;</span><span style="color: rgb(0, 0, 0);"> paramNum) </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> sql;<br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">2 如果有参数，则是动态SQL语句</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        StringBuffer returnSQL </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);"> StringBuffer();<br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);">        String[] subSQL </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> sql.split(</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);">);<br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(0, 0, 0);">        </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);"> </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);"> paramNum; i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">) {<br /></span><span style="color: rgb(0, 128, 128);">16</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);"> (params[i] </span><span style="color: rgb(0, 0, 255);">instanceof</span><span style="color: rgb(0, 0, 0);"> Date) {<br /></span><span style="color: rgb(0, 128, 128);">17</span> <span style="color: rgb(0, 0, 0);">                returnSQL.append(subSQL[i]).append(</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);">).append(MyDateUtil.dateUtil2SQL((java.util.Date)params[i])).append(</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);">);<br /></span><span style="color: rgb(0, 128, 128);">18</span> <span style="color: rgb(0, 0, 0);">            } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br /></span><span style="color: rgb(0, 128, 128);">19</span> <span style="color: rgb(0, 0, 0);">                returnSQL.append(subSQL[i]).append(</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);">).append(params[i]).append(</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);">);<br /></span><span style="color: rgb(0, 128, 128);">20</span> <span style="color: rgb(0, 0, 0);">            }<br /></span><span style="color: rgb(0, 128, 128);">21</span> <span style="color: rgb(0, 0, 0);">        }<br /></span><span style="color: rgb(0, 128, 128);">22</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">23</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);"> (subSQL.length </span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> params.length) {<br /></span><span style="color: rgb(0, 128, 128);">24</span> <span style="color: rgb(0, 0, 0);">            returnSQL.append(subSQL[subSQL.length </span><span style="color: rgb(0, 0, 0);">-</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, 128, 128);">25</span> <span style="color: rgb(0, 0, 0);">        }<br /></span><span style="color: rgb(0, 128, 128);">26</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> returnSQL.toString();<br /></span><span style="color: rgb(0, 128, 128);">27</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);">28</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">29</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">30</span> <span style="color: rgb(0, 128, 0);">     * 为PreparedStatement预编译的SQL语句设置参数<br /></span><span style="color: rgb(0, 128, 128);">31</span> <span style="color: rgb(0, 128, 0);">     * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> pstmt<br /></span><span style="color: rgb(0, 128, 128);">32</span> <span style="color: rgb(0, 128, 0);">     * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> params<br /></span><span style="color: rgb(0, 128, 128);">33</span> <span style="color: rgb(0, 128, 0);">     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">34</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> setParams(PreparedStatement pstmt, Object[] params) {<br /></span><span style="color: rgb(0, 128, 128);">35</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);"> (</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> params) {<br /></span><span style="color: rgb(0, 128, 128);">36</span> <span style="color: rgb(0, 0, 0);">                </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);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, paramNum </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> params.length; i </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> paramNum; i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">) {<br /></span><span style="color: rgb(0, 128, 128);">37</span> <span style="color: rgb(0, 0, 0);">                    </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br /></span><span style="color: rgb(0, 128, 128);">38</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);"> (</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> params[i] </span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">39</span> <span style="color: rgb(0, 0, 0);">                            params[i] </span><span style="color: rgb(0, 0, 255);">instanceof</span><span style="color: rgb(0, 0, 0);"> java.util.Date) {<br /></span><span style="color: rgb(0, 128, 128);">40</span> <span style="color: rgb(0, 0, 0);">                            pstmt.setDate(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);">1</span><span style="color: rgb(0, 0, 0);">, MyDateUtil.dateUtil2SQL(<br /></span><span style="color: rgb(0, 128, 128);">41</span> <span style="color: rgb(0, 0, 0);">                                    (java.util.Date) params[i]));<br /></span><span style="color: rgb(0, 128, 128);">42</span> <span style="color: rgb(0, 0, 0);">                        } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br /></span><span style="color: rgb(0, 128, 128);">43</span> <span style="color: rgb(0, 0, 0);">                            pstmt.setObject(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);">1</span><span style="color: rgb(0, 0, 0);">, params[i]);<br /></span><span style="color: rgb(0, 128, 128);">44</span> <span style="color: rgb(0, 0, 0);">                        }<br /></span><span style="color: rgb(0, 128, 128);">45</span> <span style="color: rgb(0, 0, 0);">                    } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (SQLException e) {<br /></span><span style="color: rgb(0, 128, 128);">46</span> <span style="color: rgb(0, 0, 0);">                        </span><span style="color: rgb(0, 0, 255);">throw</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);"> MySQLException(e);<br /></span><span style="color: rgb(0, 128, 128);">47</span> <span style="color: rgb(0, 0, 0);">                    }<br /></span><span style="color: rgb(0, 128, 128);">48</span> <span style="color: rgb(0, 0, 0);">                }<br /></span><span style="color: rgb(0, 128, 128);">49</span> <span style="color: rgb(0, 0, 0);">            }<br /></span><span style="color: rgb(0, 128, 128);">50</span> <span style="color: rgb(0, 0, 0);">    }</span></span></div><br />然后轻松核实你的控制台或者日志文件吧......<br /></span><img src ="http://www.blogjava.net/crazycy/aggbug/59581.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/crazycy/" target="_blank">crazycy</a> 2006-07-22 21:53 <a href="http://www.blogjava.net/crazycy/archive/2006/07/22/59581.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>An internal error occurred during: "Generating Artifacts" </title><link>http://www.blogjava.net/crazycy/archive/2006/06/22/54502.html</link><dc:creator>crazycy</dc:creator><author>crazycy</author><pubDate>Thu, 22 Jun 2006 07:41:00 GMT</pubDate><guid>http://www.blogjava.net/crazycy/archive/2006/06/22/54502.html</guid><wfw:comment>http://www.blogjava.net/crazycy/comments/54502.html</wfw:comment><comments>http://www.blogjava.net/crazycy/archive/2006/06/22/54502.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/crazycy/comments/commentRss/54502.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/crazycy/services/trackbacks/54502.html</trackback:ping><description><![CDATA[    今天是用Eclipse3.1.2+MyEclipse4.1.1+MySQL5.0.12，用Database Explorer创建Hibernate3所需的HBM映射文件和VO对象时，居然报An internal error occurred during: "Generating Artifacts" 这个错误。<br /><br />    google了一把，看到Blog（软道，url：http://blog.csdn.net/langtaojin/archive/2006/03/28/641722.aspx）介绍如下：<br />今天在使用myEclipse 的　Database Explorer 视图中Create Hibernate Mapping时，出现了“An internal error occurred during: "Generating Artifacts".”错误提示。费了好大劲，终于解决了。据myEclipse官方网站上的介绍，发生该错误主要有两种情况，一是你eclipse上安装了jboss公司的hibernate tools plugin for eclipse,这些插件与myEclipse发生冲突，解决方法是删除这些插件。二是你在没有卸载以前myEclipse版本的情况下安装了新的 myEclipse版本，解决方法是把myEclipse卸载后重新安装，我遇到的情况就属于每二种情况，重装myEclipse后问题解决了。<br /><br />    第一个问题不存在，然后咣咣的卸载、安装了MyEclipse4.1.1。问题依然。<br /><br />    手工建立测试表，却没有这个问题。突然想到了可能是数据表建立的格式有问题：我用PD直接把物理实体模型导入到Mysql中。就它了。通过MyCC（当然也可以通过命令行 mysql -h localhost -u root -p）把PD生成的SQL语句重新运行，OK，问题解决。<br /><br />    结合上面的blog，可以看出出现这个问题具有三种情况了。<br /><br />    当然或许你用Oracle，也可能遇到这个问题，如果以上三种情况都没有解决了An internal error occurred during: "Generating Artifacts" 这个错误。你注意两点：1PLSQL工具的问题，建议直接命令行。2Orcle的class12驱动的版本，建议换新版本。<br /><br /><br /><img src ="http://www.blogjava.net/crazycy/aggbug/54502.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/crazycy/" target="_blank">crazycy</a> 2006-06-22 15:41 <a href="http://www.blogjava.net/crazycy/archive/2006/06/22/54502.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>