<?xml version="1.0" encoding="GBK"?>
<?xml-stylesheet href="/style/rss.css" type="text/css"?>
<rss version="2.0" xmlns:eb="http://blog.tom.com/">
<channel>
  <title>岁月悠悠</title>
  <link>http://blog.tom.com/hoohey</link>
  <description><![CDATA[那些青葱往事徜徉成一条河,平静地流过我的岁月.左岸是我无法忘却的回忆,右岸是我值得紧握的璀璨年华,而中间飞快流淌的,是我年年岁岁淡淡的感伤! ]]></description>
  <language>zh</language>
  <generator>newblog.tom.com RSS</generator>
  <pubDate></pubDate>    <item>
		<title><![CDATA[ Tomcat问题 ]]></title>
		<link>http://blog.tom.com/hoohey/article/1579.html</link>
		<description><![CDATA[ <p><br>
把今天的状况总结一下，如果以后谁遇到了类似的情况，还可以参考一下，节约时间。<br>
&nbsp;&nbsp; 用Tomcat，启动服务器时，遇到报错为如下消息：<br>
信息：The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:Program FilesJavajre1.5.0_09bin;.;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:Program FilesATI TechnologiesATI Control Panel;C:Program FilesMicrosoft SQL Server80ToolsBINN;C:Program FilesMicrosoft SQL Server90Toolsbinn;C:Program FilesCommon FilesAdobeAGL;C:Program FilesMicrosoft Visual Studio .NET 2003SDKv1.1Bin;C:WINDOWSMicrosoft.NETFrameworkv1.1.4322;D:Program FilesJavajdk1.5.0_09bin;.<br>
2007-3-7 17:18:12 org.apache.coyote.http11.Http11BaseProtocol init<br>
严重：Error initializing endpoint<br>
这时的解决措施可以是：去下载一个tcnative-1.dll文件，放在C:WINDOWSsystem32里，再重新启动服务器，看服务器是否能正常启动。<br>
如果服务器启动时，没有报前面的错，而是报出另外的错误，如以下信息：<br>
严重: An incompatible version 1.1.1 of the Apache Tomcat Native library is installed, while Tomcat requires version 1.1.3<br>
2007-3-7 17:39:33 org.apache.catalina.core.AprLifecycleListener lifecycleEvent<br>
信息: An older version 1.1.1 of the Apache Tomcat Native library is installed, while Tomcat recommends version greater than 1.1.4<br>
这说明tcnative-1.dll文件版本太低，需下载一个高于1.1.4版本的文件。<br>
你可以下载<a href="http://tomcat.heanet.ie/native/1.1.8/binaries/win32/%20tcnative-1.dll" target="_blank">http://tomcat.heanet.ie/native/1.1.8/binaries/win32/ tcnative-1.dll</a>&nbsp; 该.dll文件为1.1.8版本。<br>
至于文件放的位置有两种选择，<br>
1、把文件放入C:WINDOWSsystem32里。我就是这样解决的。<br>
2、把它放在环境变量path中所指向的jdk的bin的目录下，例如，放在C: Javajdk1.5.0_09bin目录下。</p> ]]></description>
		<eb:creationDate>2007-04-23 18:21:11</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ struts多模块 ]]></title>
		<link>http://blog.tom.com/hoohey/article/1578.html</link>
		<description><![CDATA[ <br>
这两天网站才刚开始做,刚开始做就碰到一个问题,因为用的是struts+hibernate,前台和后台我给做成多模块的,多摸块出现了一个问题,就是我的action找不到mapping,找了很久才发现原因:<br>
&nbsp;<br>
ModuleConfig mc = (ModuleConfig)application.getAttribute(Globals.MODULE_KEY+"<font color="#FF0000">/</font><font color="#FF0000">moduleName</font>");<br>
request.setAttribute(Globals.MODULE_KEY,mc);<br>
&nbsp;<br>
如果不加这句,它不会到指定的模块配置文件里去找,只是到默认的模块里找.那么Globals.MODULE_KEY就是默认的/根目录模块,所以始终无法在struts-config-module.xml里找到对应的action的Path.只是在struts-config.xml里找,但是如果你在用超链接的话因为${pageContext.request.contextPath}/module/action.do,加了module所以能找到,我就是因为这个原因一直认为可以找到对应的struts-config-module.xml文件,所以郁闷了很久.....问题解决了 ]]></description>
		<eb:creationDate>2007-03-26 15:25:00</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ Linux基本命令 ]]></title>
		<link>http://blog.tom.com/hoohey/article/1577.html</link>
		<description><![CDATA[ <p><strong>简单罗列一些总结</strong></p>
<p><br>
&nbsp;1、linux做JAVA开发<br>
&nbsp;&nbsp; unix:sun:solaris/Hp:hp-ux/ibm:aix 都在做UNIX操作系统（收费）内核都不一样<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; freebsd/openbsd/netbsd(免费)<br>
&nbsp;&nbsp; linux:redhat /suse /ul&nbsp; 各厂商内核是一样的,现在内核到2。6了<br>
&nbsp;&nbsp;&nbsp; Redhat:个人版7.2 7.3 8 9<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 企业版:as 2.1 3 4<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp; 安装:cdrom 硬盘 网络:(nfs/http/ftp) 无人制:kickstart<br>
&nbsp;&nbsp;&nbsp; 虚拟:vmware/vpc(tools)<br>
&nbsp;&nbsp;&nbsp; 基本命令:<br>
&nbsp;&nbsp;&nbsp; 远程管理工具：命令行工具:telnet 23端口(同windows)&nbsp;&nbsp;&nbsp; ssh:secure shell<br>
&nbsp;&nbsp;&nbsp; 图形界面:vnc<br>
&nbsp;&nbsp;&nbsp; 配置JAVA环境：安装JDK tomcat/weblogic/jboss<br>
&nbsp;&nbsp;&nbsp; 安装方法：源码安装 二进制安装：rpm:redhat package/management<br>
&nbsp;&nbsp;&nbsp; 命令：<br>
&nbsp;&nbsp;&nbsp; [root@localhost soft]#rpm -ivh jdk-1_5_0_06-linux-i586.rpm<br>
&nbsp;&nbsp;&nbsp; //i:install v:verbose h:hash、<br>
--1.1 Linux系统文件结构<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /bin:所有用户都可以使用的命令所在位置（系统默认的命令）<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 用户：普通用户， 管理员用户(root)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /sbin:只有管理员可以使用的命令<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /boot:内核所在的位置<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /dev:设备文件所在目录 /dev/sda /dev/hda<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /etc:配置文件所在目录<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /home:用户主目录(包括用户的配置文件信息，用户登录后最先目录)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /initrd:虚拟设备<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /lost+found:回收站<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /lib:库目录<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /mnt:光盘或软盘的加载点 ，通过mount命令来加载<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /opt:第三方软件安装目录<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /root:root帐号主目录<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /tmp:临时文件<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /usr:用户目录：用户安装的文件<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /var:保存的文件大小不确定的（日志文件、邮件、。）<br>
--1.2Linux命令集<br>
&nbsp; --1.2.1 Linux基本命令<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1)IP地址设置：netconfig 设置完了以后用service network restart<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2)显示IP地址：ifconfig<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3)修改分辨率: redhat-config-xfree86<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4)关机:init 0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5)显示当前目录：pwd<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6)显示目录内容：ls //list(dir)黑色：表示文件 兰色表示：目录<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ls -l//cd显示详细信息，-代表文件&nbsp; d:表示directory<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7)生成目录：mkdir&nbsp; (make directory) e.g:mkdir /testl<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8)进入目录: cd /dirname&nbsp; e.g:cd /zb 进入文件夹<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8)拷贝文件：cp e.g:cp /etc/yp.conf .&nbsp; //拷贝到当前目录<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 9）删除：rm -rf&nbsp; [filename or dirname]<br>
&nbsp;&nbsp;rm:remove r:可以删除目录 f:不需要确认<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10)移动或改名:mv&nbsp; e.g: mv 1.txt 2.txt(改名)&nbsp; 只有移动到另一目录才是移动 e.g: mv 1.txt abc<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 11)文件编辑命令：vi<br>
&nbsp;1、命令模式&nbsp; esc<br>
&nbsp;2、插入模式&nbsp; i<br>
&nbsp;3、末行模式&nbsp; :<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #vi filename<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 命令---插入 i<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 插入---命令 esc<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 命令模式---末行模式:wq&nbsp; q!不存盘退出 wq!强制存盘<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 查看内容：cat filename<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 查找命令：/内容&nbsp;&nbsp; n向下查&nbsp; N向上查<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ***命令模式下<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 删除一行：dd<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 复制一行：yy<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 粘贴：p<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 撤消：u<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;***末行模式下<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 　显示行号：set nu<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 统计文件的行数:wc -l filename<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;查找文件：find dirname -name "keyword"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.g:find /etc -name "*.conf" (查找etc目录下的所有.conf扩展名的文件，-name表示根据名字查找)<br>
&nbsp; 对文件内容做查找操作，找含有特定关键字的所有行:grep<br>
&nbsp;&nbsp;&nbsp;e.g:grep root /etc/passwd (在passwd文件中查找含有root关键字的所有行)<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 12)自动补齐命令键：tad　e.g：mkd以后你按tab键，会给你谈出所有相关命令<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 13)ftp lftp gftp<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 14)对输出结果排序,不影响原文件：sort filename&nbsp; 反向排序 sort -r filename<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 15)对结果去点连续重复的行，不影响原文件：uniq filename<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 16)新建空文件：touch filename<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 17)改变文件的所有者：chown username:groupname filename&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.g: chown root:zb /home/zb/f4<br>
&nbsp; 改变组:chgrp groupname filename<br>
&nbsp; 查看文件所有者：ls -l<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 18)软件包管理(类似WINDOWS下的添加删除程序):redhat-config-packages<br>
&nbsp;<br>
&nbsp; --1.2.2 Linux下java使用<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1)设置ＪＡＶＡ环境　修改配置文件/etc/profile&nbsp; e.g:vi /etc/profile<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 环境变量是区分大小写的，路径是冒号分隔，（windows下是分号）<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 配置好以后让它立即生效的话用：soruce /etc/profile&nbsp; (重起系统也可以)<br>
　　 　2)压缩文件：.gz .bz2&nbsp; .rar&nbsp; .zip<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.g: unzip ja....zip&nbsp; (unzip解压。）<br>
　　　 3)安装Tomcat 进入到bin目录，执行添加权限操作：chmod u+x *&nbsp; 给所有文件执行权限<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bin/startup.sh&nbsp; (这是tomcat的启动，windows下是.bat文件)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp; --1.2.3用户管理<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1)用户信息存在/etc/passwd文件下<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;查看用户信息:cat /etc/passwd<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2)创建用户: useradd username<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3)切换用户:su - username<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4)设置密码：passwd username&nbsp; 管理员使用<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;passwd 个人用户自己修改自己密码<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5)删除用户：userdel username&nbsp;&nbsp;&nbsp; 只删除用户 在/home下还有用户目录<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;userdel -r username 删除用户和用户主目录<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6)查看当前用户：whoami<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7)查看用户信息：id username<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8)查看已经登录的用户:who<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 9)伪终端：pts/0<br>
&nbsp;<br>
&nbsp; --1.2.4 telnet服务<br>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;1、cd /etc/xinetd.d<br>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;2、vi krb5-telnet<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; 把disable = yes 改为no<br>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;3、重复xinetd服务，是一个管理服务 service xinetd restart<br>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;4、cnkconfig --list查看列表<br>
&nbsp;<br>
&nbsp; --1.2.5 打包归档命令 tar<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 打包：tar -cvf filename.tar filelist(*.conf)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.g:tar -cvf 1.tar filename1 filename2<br>
&nbsp;展开：tar -xvf filename.tar<br>
&nbsp;e.g:tar -xvf 1.tar<br>
&nbsp;&nbsp;&nbsp; tar命令不做压缩操作，如果要压缩的话得用到压缩工具：gzip bzip2<br>
&nbsp;&nbsp;&nbsp;&nbsp; gzip filename: 压缩后的文件是filename.gz<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bzip2 filename:filename.bz2<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;解压：<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gzip -d filename.gz<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bzip2 -d filename.bz2<br>
&nbsp;&nbsp;&nbsp; &nbsp;如果要又压缩，又打包：tar -czvf filename.tar.gz filelist<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;解压：tar -xzvf filename.tar.gz<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp; --1.2.6 Linux下MYSQL安装<br>
&nbsp;&nbsp;&nbsp;&nbsp; 1、通过光盘安装：redhat-config-packages 系统盘安装<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp; &nbsp;2、下载mysql.tar.gz<br>
&nbsp;&nbsp;&nbsp; &nbsp;3、# tar -xzvf mysql<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;# useradd mysql<br>
<br>
&nbsp;&nbsp;&nbsp; /**<br>
&nbsp;&nbsp;&nbsp;&nbsp; *&nbsp;&nbsp; 这几步是出于安全考虑<br>
&nbsp;&nbsp;&nbsp;&nbsp; *<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; scripts/mysql_install_db --user=mysql<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; chown -R root mysql-max-5.0.11-beta-linux-i686<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;chown -R mysql data<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chgrp -R mysql mysql-max-5.0.11-beta-linux-i686<br>
&nbsp;&nbsp;&nbsp;&nbsp; */<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4、/bin/safe_mysqld --user=mysql :运行</p> ]]></description>
		<eb:creationDate>2007-03-04 13:56:02</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ JavaMail ]]></title>
		<link>http://blog.tom.com/hoohey/article/1574.html</link>
		<description><![CDATA[ <br>
时间:<font color="#FF0000">2006-12-10~~~~2006-12-11</font><br>
<br>
<font color="#FF0000">学了两天,能写个发送程序....JavaMail</font><br>
import java.io.FileNotFoundException;<br>
import java.io.FileOutputStream;<br>
import java.io.IOException;<br>
import java.util.Properties;<br>
import javax.activation.DataHandler;<br>
import javax.activation.FileDataSource;<br>
import javax.mail.Authenticator;<br>
import javax.mail.Message;<br>
import javax.mail.MessagingException;<br>
import javax.mail.PasswordAuthentication;<br>
import javax.mail.Session;<br>
import javax.mail.Transport;<br>
import javax.mail.internet.InternetAddress;<br>
import javax.mail.internet.MimeBodyPart;<br>
import javax.mail.internet.MimeMessage;<br>
import javax.mail.internet.MimeMultipart;<br>
public class MsgSender {<br>
&nbsp;public static void main(String[] args) throws MessagingException {<br>
&nbsp;&nbsp;// TODO Auto-generated method stub<br>
&nbsp;&nbsp;Properties prop = new Properties();<br>
&nbsp;&nbsp;prop.setProperty("mail.transport.protocol","smtp");<br>
&nbsp;&nbsp;prop.setProperty("mail.host","192.168.1.200");<br>
&nbsp;&nbsp;prop.setProperty("mail.smtp.auth","true");<br>
&nbsp;&nbsp;Authenticator auth = new Authenticator(){<br>
&nbsp;&nbsp;&nbsp;@Override<br>
&nbsp;&nbsp;&nbsp;protected PasswordAuthentication getPasswordAuthentication(){<br>
&nbsp;&nbsp;&nbsp;&nbsp;return new PasswordAuthentication("hoohey","111111");<br>
&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;};<br>
&nbsp;&nbsp;String body = "&lt;a href=http://www.layzo.com&gt;" +<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"欢迎点击进入我们的网站&lt;/br&gt;&lt;/a&gt;"+<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"&lt;img src="cid:image"&gt;";<br>
&nbsp;&nbsp;String subject ="Test图片";<br>
&nbsp;&nbsp;Session session = Session.getInstance(prop,auth);<br>
&nbsp;&nbsp;session.setDebug(true);<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;MimeMessage msg = new MimeMessage(session);<br>
&nbsp;&nbsp;msg.setFrom(new InternetAddress("<a href="mailto:fool@tom.com">fool@tom.com</a>"));<br>
&nbsp;&nbsp;msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse("<a href="mailto:zhongbin82@126.com">zhongbin82@126.com</a>"));<br>
&nbsp;&nbsp;//如果是简单的邮件,InternetAddress.parse("<a href="mailto:zhongbin82@126.com">zhongbin82@126.com</a>")直接用"<a href="mailto:zhongbin82@126.com">zhongbin82@126.com</a>"代替就可以<br>
&nbsp;&nbsp;msg.setSubject(subject);<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;MimeMultipart multipart = new MimeMultipart("related");<br>
&nbsp;&nbsp;MimeBodyPart htmlBodyPart = new MimeBodyPart();<br>
&nbsp;&nbsp;htmlBodyPart.setContent(body,"text/html;charset=gb2312");<br>
&nbsp;&nbsp;multipart.addBodyPart(htmlBodyPart);<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;MimeBodyPart gifBodyPart = new MimeBodyPart();<br>
&nbsp;&nbsp;FileDataSource fds = new FileDataSource("d:/My Pictures/011ak.jpg");<br>
&nbsp;&nbsp;gifBodyPart.setDataHandler(new DataHandler(fds));<br>
&nbsp;&nbsp;gifBodyPart.setHeader("Content-Location","image");<br>
&nbsp;&nbsp;multipart.addBodyPart(gifBodyPart);<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;msg.setContent(multipart);<br>
&nbsp;&nbsp;msg.saveChanges();<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;Transport.send(msg);<br>
&nbsp;}<br>
}<br> ]]></description>
		<eb:creationDate>2006-12-13 16:30:54</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ Hibernate初探 ]]></title>
		<link>http://blog.tom.com/hoohey/article/1573.html</link>
		<description><![CDATA[ <br>
时间:<font color="#FF0000">2006-12-07~~~~2006-12-11<br></font> &nbsp;<br>
这一周是学Hibernate,由于上一次JDBC 没及时更新,这一周也接不上,拉下太多,导致现在不可能从头一篇篇写,这周也有两天是学JavaMail,总体来说,Hibernate好象简单一些,这里只是把自己写的一个Hibernate登陆程序贴一下,懒,改天空闲复习的时候在仔细写几篇:<br>
/**&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;*用Hibernate进行用户注册及登录练习<br>
&nbsp;*/<br>
import java.io.BufferedReader;<br>
import java.io.IOException;<br>
import java.io.InputStreamReader;<br>
import java.util.Iterator;<br>
import java.util.List;<br>
import java.util.Scanner;<br>
import org.hibernate.Query;<br>
import org.hibernate.Session;<br>
import org.hibernate.SessionFactory;<br>
import org.hibernate.cfg.Configuration;<br>
import hoohey.User;//我包里的一个持久类<br>
public class HqlTest {<br>
&nbsp;public static void main(String[] args) {<br>
&nbsp;&nbsp;String username = null;<br>
&nbsp;&nbsp;String password = null;<br>
&nbsp;&nbsp;Configuration cfg = new Configuration();<br>
&nbsp;&nbsp;cfg.addResource("User.hbm.xml");<br>
&nbsp;&nbsp;BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));<br>
&nbsp;&nbsp;Session session = null;<br>
&nbsp;&nbsp;System.out.println("登录请按1,注册用户请按2！");<br>
&nbsp;&nbsp;Scanner in = new Scanner(System.in);<br>
&nbsp;&nbsp;String pos = in.nextLine();<br>
&nbsp;&nbsp;if(pos.equals("1")){<br>
&nbsp;&nbsp;&nbsp;try {<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("请输入您的用户名：");<br>
&nbsp;&nbsp;&nbsp;&nbsp;username = reader.readLine();<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("请输入您的密码：");<br>
&nbsp;&nbsp;&nbsp;&nbsp;password = reader.readLine();<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;} catch (IOException e) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;else if(pos.equals("2")){<br>
&nbsp;&nbsp;&nbsp;String newusername=null;<br>
&nbsp;&nbsp;&nbsp;String newuserpsw =null;<br>
&nbsp;&nbsp;&nbsp;try {<br>
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("请输入您的用户名：");<br>
&nbsp;&nbsp;&nbsp;&nbsp;newusername = reader.readLine();<br>
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("请输入您的密码：");<br>
&nbsp;&nbsp;&nbsp;&nbsp;newuserpsw = reader.readLine();<br>
&nbsp;&nbsp;&nbsp;} catch (IOException e) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br>
&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;SessionFactory factory = cfg.buildSessionFactory();<br>
&nbsp;&nbsp;&nbsp;session = factory.getCurrentSession();<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;User u = new User();<br>
&nbsp;&nbsp;&nbsp;u.setUsername(newusername);<br>
&nbsp;&nbsp;&nbsp;u.setPassword(newuserpsw);<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;session.beginTransaction();<br>
&nbsp;&nbsp;&nbsp;session.saveOrUpdate(u);<br>
&nbsp;&nbsp;&nbsp;session.getTransaction().commit();<br>
&nbsp;&nbsp;&nbsp;System.out.println("恭喜您,注册成功!");<br>
&nbsp;&nbsp;&nbsp;return;<br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;else {<br>
&nbsp;&nbsp;&nbsp;System.out.println("您将退出!");<br>
&nbsp;&nbsp;&nbsp;System.exit(1);<br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;try {<br>
&nbsp;&nbsp;&nbsp;SessionFactory factory = cfg.buildSessionFactory();<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;session = factory.getCurrentSession();<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;session.beginTransaction();<br>
&nbsp;&nbsp;&nbsp;Query q = session.createQuery("from vo.User as User where User.username=&nbsp; and User.password=&nbsp;");<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;q.setString(0,username);//注入第一个&nbsp;号的值,Hibernate中是0，而JDBC是从1开始.<br>
&nbsp;&nbsp;&nbsp;q.setString(1,password);<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;List l = q.list(); //将取的的结果存入List<br>
&nbsp;&nbsp;&nbsp;Iterator it = l.iterator(); //List产生一个进行迭代器, 下面进行迭代<br>
&nbsp;&nbsp;&nbsp;User u = null;<br>
&nbsp;&nbsp;&nbsp;if(it.hasNext()){<br>
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("登录成功!");<br>
&nbsp;&nbsp;&nbsp;&nbsp;u = (User)it.next();<br>
&nbsp;&nbsp;&nbsp;}else<br>
&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("用户名或密码有误!");<br>
&nbsp;&nbsp;&nbsp;&nbsp;System.exit(1);<br>
&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;session.getTransaction().commit();<br>
&nbsp;&nbsp;&nbsp;//因为是currentSession,确保只有一个session,所以commit自动关闭，无需close().<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;System.out.println("修改用户名请按1,修改密码请按2！");<br>
&nbsp;&nbsp;&nbsp;String num = reader.readLine();<br>
&nbsp;&nbsp;&nbsp;if(num.equals("1")){<br>
&nbsp;&nbsp;&nbsp;System.out.println("填入您的新用户名：");<br>
&nbsp;&nbsp;&nbsp;String newUser = reader.readLine();<br>
&nbsp;&nbsp;&nbsp;u.setUsername(newUser);<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;session = factory.getCurrentSession();<br>
&nbsp;&nbsp;&nbsp;session.beginTransaction();<br>
&nbsp;&nbsp;&nbsp;session.saveOrUpdate(u);<br>
&nbsp;&nbsp;&nbsp;session.getTransaction().commit();<br>
&nbsp;&nbsp;&nbsp;System.out.println("用户名修改成功!");<br>
&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;else if(num.equals("2"))<br>
&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;System.out.println("填入您的新密码：");<br>
&nbsp;&nbsp;&nbsp;String newPw = reader.readLine();<br>
&nbsp;&nbsp;&nbsp;u.setPassword(newPw);<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;session = factory.getCurrentSession();<br>
&nbsp;&nbsp;&nbsp;session.beginTransaction();<br>
&nbsp;&nbsp;&nbsp;session.saveOrUpdate(u);<br>
&nbsp;&nbsp;&nbsp;session.getTransaction().commit();<br>
&nbsp;&nbsp;&nbsp;System.out.println("密码修改成功!");&nbsp;<br>
&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;else{<br>
&nbsp;&nbsp;&nbsp;&nbsp;System.exit(1);<br>
&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;} catch (Exception ex) {<br>
&nbsp;&nbsp;&nbsp;ex.printStackTrace();<br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<br>
&nbsp;}<br>
}<br>
<br>
&nbsp;<br>
还有个Demo,对<font color="#0000FF">数据库进行操作</font>(hibernate)<br>
import hoohey.User;<br>
import java.sql.Timestamp;<br>
import org.hibernate.HibernateException;<br>
import org.hibernate.Session;<br>
import org.hibernate.SessionFactory;<br>
import org.hibernate.cfg.Configuration;<br>
<br>
public class Demo{<br>
&nbsp;<br>
&nbsp;public static void main(String[] args){<br>
&nbsp;&nbsp;Configuration cfg = new Configuration();<br>
&nbsp;&nbsp;cfg.addClass(User.class);<br>
//&nbsp;&nbsp;**上面可以cfg.addResource("hoohey/User.hbm.xml"),所以.hbm.xml也是可以改名字的(路径/文件名.xml)<br>
//&nbsp;&nbsp;也可以在配置文件seesion-factory加&lt;mapping resource="映射文件",那样的话该行要省略<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;cfg.configure("hoohey/hibernate.xml");<br>
//&nbsp;&nbsp;如果是引入hibernate.properties文件,这句话就不需要<br>
//&nbsp;&nbsp;**如果.cfg.xml文件改了名字的话要在上面这句括号里("路径/文件名.xml")<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;Session session = null;<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;try {<br>
&nbsp;&nbsp;&nbsp;SessionFactory factory = cfg.buildSessionFactory();<br>
&nbsp;&nbsp;&nbsp;session =factory.openSession();<br>
/***********************查找一条纪录**********************/&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;User u = (User)session.load(User.class,new Integer(2));<br>
&nbsp;&nbsp;&nbsp;System.out.println("UserName:"+u.getUsername());<br>
/***********************增加一条纪录**********************/&nbsp;&nbsp;&nbsp;<br>
/*&nbsp;&nbsp;&nbsp;User u =new User();<br>
&nbsp;&nbsp;&nbsp;u.setUsername("bibobi");<br>
&nbsp;&nbsp;&nbsp;u.setPassword("bibobi");<br>
&nbsp;&nbsp;&nbsp;u.setLogintimes(new Integer(1));<br>
//上句将这个设成Integer是有原因的，如果上面这句没有，而logintimes是int型的话，就算你只查入username也会往数据库插一个0值，而Integer不会<br>
&nbsp;&nbsp;&nbsp;u.setLogintime(new Timestamp(System.currentTimeMillis()));<br>
&nbsp;&nbsp;&nbsp;session.beginTransaction();<br>
&nbsp;&nbsp;&nbsp;session.save(u);<br>
&nbsp;&nbsp;&nbsp;session.getTransaction().commit();*/<br>
/***********************修改一条纪录**********************/&nbsp;<br>
/*&nbsp;&nbsp;&nbsp;User u = (User)session.load(User.class,new Integer(7));<br>
&nbsp;&nbsp;&nbsp;u.setUsername("j2ee");<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;session.beginTransaction();<br>
&nbsp;&nbsp;&nbsp;session.update(u);&nbsp; //also could use save(u)<br>
&nbsp;&nbsp;&nbsp;session.getTransaction().commit();*/<br>
&nbsp;&nbsp;&nbsp;<br>
/***********************删除一条纪录**********************/<br>
/*&nbsp;&nbsp;&nbsp;User u = (User)session.load(User.class,new Integer(10));<br>
&nbsp;&nbsp;&nbsp;session.beginTransaction();<br>
&nbsp;&nbsp;&nbsp;session.delete(u);<br>
&nbsp;&nbsp;&nbsp;session.getTransaction().commit(); */<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;} catch (HibernateException e) {<br>
&nbsp;&nbsp;&nbsp;e.printStackTrace();<br>
&nbsp;&nbsp;&nbsp;session.getTransaction().rollback();<br>
&nbsp;&nbsp;}finally{<br>
&nbsp;&nbsp;&nbsp;if(session!=null){<br>
&nbsp;&nbsp;&nbsp;session.close();<br>
&nbsp;&nbsp;&nbsp;session = null;<br>
&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;<br>
&nbsp;}<br>
}<br>
&nbsp;<br>
大部分Hibernate的内容都有体现,Hibernate重要知识点:<br>
两大知识点，对象三种状态及主键<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;临时状态 脱管状态 持久状态<br>
0、知道如何在不使用默认文件名时，也能配置Hibernate<br>
如果在配置文件中加了&lt;maping 映射文件&gt;那么可以不用再addClass<br>
&nbsp;&nbsp;&nbsp;&nbsp; 掌握SessionFactory和Session在编程时应该注意什么问题。<br>
1、对象的三种状态分别是什么？有什么含义？<br>
2、update方法与merge方法的区别，应用场合分别是什么？<br>
3、saveOrUpdate方法应用场合？什么时候执行save&nbsp;什么时候执行update&nbsp;<br>
unsaved-value<br>
4、主键生成器是什么意思？为什么实体一定要有标识符？<br>
　如果数据库表中没有主键，能否映射对象？<br>
5、HQL，Hibernate Query Lange，要求必须要非常熟练地掌握<br>
<br> ]]></description>
		<eb:creationDate>2006-12-13 16:18:25</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ JDBC第六天 ]]></title>
		<link>http://blog.tom.com/hoohey/article/1572.html</link>
		<description><![CDATA[ <BR><br />西风烈，长空雁叫霜晨月。<br />霜晨月，马蹄声碎，喇叭声咽。<br />雄关漫道真如铁，而今迈步从头越。<br />从头越，苍山如海，残阳如血。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ---李敖<br />趁中午休息时间，读了李大师的几首诗，甚是感动，虽然不太喜欢他狂妄、目空一切的个性，但是这些东西正是我缺之又缺的，<br />一个人要想成点事，自信是必不可少的，那么就有所改变吧！从头越，苍山如海，残阳如血....你体会到了么.... <br />&nbsp; <br />时间 ：<font color="#ff0000">2006-12-05</font>&nbsp; 内容 ：<font color="#ff0000">行集、离线结果集、ORM</font> <font color="#ff0000"></font><br /><br />BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));//这个reader 也是要关闭的 <br /><br />一个结果集处理小demo(步骤详细说明)<br />public class Demo { <br />&nbsp;public static String filter(String str) {<br />&nbsp;&nbsp;return str.replaceAll("'", "''"); <br />&nbsp;} <br />&nbsp;public static void main(String[] args) {<br />&nbsp;&nbsp;/*<br />&nbsp;&nbsp; * 事先声明连接、语句、结果集，为了可以在finally中关闭资源<br />&nbsp;&nbsp; */<br />&nbsp;&nbsp;Connection conn = null;<br />&nbsp;&nbsp;PreparedStatement stmt = null;<br />&nbsp;&nbsp;ResultSet rs = null;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;BufferedReader reader = null;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;String username = null, password = null; <br />&nbsp;&nbsp;try {<br />&nbsp;&nbsp;&nbsp;System.out.println("请输入用户名：");<br />&nbsp;&nbsp;&nbsp;byte[] buf = new byte[128];<br />&nbsp;&nbsp;&nbsp;int len = System.in.read(buf);<br />&nbsp;&nbsp;&nbsp;username = new String(buf, 0, len<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- System.getProperty("line.separator").length()); <br />&nbsp;&nbsp;&nbsp;System.out.println("请输入密码：");<br />&nbsp;&nbsp;&nbsp;len = System.in.read(buf);<br />&nbsp;&nbsp;&nbsp;password = new String(buf, 0, len<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- System.getProperty("line.separator").length());<br />&nbsp;&nbsp;} catch (IOException e1) {<br />&nbsp;&nbsp;&nbsp;e1.printStackTrace();<br />&nbsp;&nbsp;} <br />&nbsp;&nbsp;if (username == null || password == null) {<br />&nbsp;&nbsp;&nbsp;System.out.println("用户名、密码不能为空！");<br />&nbsp;&nbsp;&nbsp;System.exit(1);<br />&nbsp;&nbsp;} <br />&nbsp;&nbsp;try {<br />&nbsp;&nbsp;&nbsp;// 第一步，加载驱动程序<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;Class.forName("com.mysql.jdbc.Driver"); <br />&nbsp;&nbsp;&nbsp;// 第二步，由DriverManger获取连接<br />&nbsp;&nbsp;&nbsp;conn = DriverManager.getConnection(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"jdbc:mysql://localhost:3306/j2ee", "root", "root");<br />&nbsp;&nbsp;&nbsp;conn.setAutoCommit(false);<br />&nbsp;&nbsp;&nbsp;// 第三步，由连接生成语句<br />&nbsp;&nbsp;&nbsp;String sql = "select * from users where username=&nbsp; and password=&nbsp;";<br />&nbsp;&nbsp;&nbsp;stmt = conn.prepareStatement(sql,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ResultSet.TYPE_SCROLL_INSENSITIVE,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ResultSet.CONCUR_UPDATABLE); <br />&nbsp;&nbsp;&nbsp;stmt.setString(1, username);<br />&nbsp;&nbsp;&nbsp;stmt.setString(2, password); <br />&nbsp;&nbsp;&nbsp;// 第四步，执行语句，并生成结果集 <br />&nbsp;&nbsp;&nbsp;rs = stmt.executeQuery(); <br />&nbsp;&nbsp;&nbsp;// 第五步，对结果集进行迭代<br />&nbsp;&nbsp;&nbsp;if (rs.next()) {<br />&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Welcome!");<br />&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("请输入新密码：");<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;/**********************使用结果集修改记录***********************<br />&nbsp;&nbsp;&nbsp;&nbsp; * <br />&nbsp;&nbsp;&nbsp;&nbsp; **********************************************************/<br />&nbsp;&nbsp;&nbsp;&nbsp;reader = new BufferedReader(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new InputStreamReader(System.in));<br />&nbsp;&nbsp;&nbsp;&nbsp;String newPw = reader.readLine();<br />&nbsp;&nbsp;&nbsp;&nbsp;//首先，更新要修改字段值<br />&nbsp;&nbsp;&nbsp;&nbsp;rs.updateString("password", newPw);<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;//其次，一定要将修改的结果提交<br />&nbsp;&nbsp;&nbsp;&nbsp;rs.updateRow();<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;/****************使用结果集插入记录**********************<br />&nbsp;&nbsp;&nbsp;&nbsp; * <br />&nbsp;&nbsp;&nbsp;&nbsp; ****************************************************/<br />&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("请输入新用户名：");<br />&nbsp;&nbsp;&nbsp;&nbsp;String newUser = reader.readLine();<br />&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("请输入新用户名密码：");<br />&nbsp;&nbsp;&nbsp;&nbsp;String newUserPw = reader.readLine();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;//首先，要将游标移动到可插入记录的位置<br />&nbsp;&nbsp;&nbsp;&nbsp;rs.moveToInsertRow();<br />&nbsp;&nbsp;&nbsp;&nbsp;//其次，修改插入记录的位置上的各个字段值<br />&nbsp;&nbsp;&nbsp;&nbsp;rs.updateString("username", newUser);<br />&nbsp;&nbsp;&nbsp;&nbsp;rs.updateString("password", newUserPw);<br />&nbsp;&nbsp;&nbsp;&nbsp;rs.updateTimestamp("loginTime", new Timestamp(System.currentTimeMillis()));<br />&nbsp;&nbsp;&nbsp;&nbsp;//第三，插入记录<br />&nbsp;&nbsp;&nbsp;&nbsp;rs.insertRow();<br />&nbsp;&nbsp;&nbsp;&nbsp;//最后，再将游标移回到原来的位置上。<br />&nbsp;&nbsp;&nbsp;&nbsp;rs.moveToCurrentRow();<br />&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("insert successfully!");<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;/************************使用结果集删除记录*******************<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br />&nbsp;&nbsp;&nbsp;&nbsp; ***********************************************************/<br />&nbsp;&nbsp;&nbsp;&nbsp;//首先，将游标移动到要删除记录的位置<br />&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("请输入删除行号：");<br />&nbsp;&nbsp;&nbsp;&nbsp;String num = reader.readLine();<br />&nbsp;&nbsp;&nbsp;&nbsp;rs.absolute(Integer.parseInt(num));<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;//第二，删除记录，无须指明删除条件<br />&nbsp;&nbsp;&nbsp;&nbsp;rs.deleteRow();<br />&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("删除成功!");<br />&nbsp;&nbsp;&nbsp;} else {<br />&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Failed!");<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;conn.commit(); <br />&nbsp;&nbsp;} catch (ClassNotFoundException e) {<br />&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;} catch (Exception e) {<br />&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;&nbsp;try {<br />&nbsp;&nbsp;&nbsp;&nbsp;conn.rollback();<br />&nbsp;&nbsp;&nbsp;} catch (SQLException e1) {<br />&nbsp;&nbsp;&nbsp;&nbsp;e1.printStackTrace();<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;} finally {<br />&nbsp;&nbsp;&nbsp;// 第六步，关闭所有资源，并保证每个资源的关闭至少被执行一次<br />&nbsp;&nbsp;&nbsp;try {<br />&nbsp;&nbsp;&nbsp;&nbsp;if (rs != null) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rs.close();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rs = null;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;} catch (SQLException e) {<br />&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;try {<br />&nbsp;&nbsp;&nbsp;&nbsp;if (stmt != null) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stmt.close();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stmt = null;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;} catch (SQLException e) {<br />&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;try {<br />&nbsp;&nbsp;&nbsp;&nbsp;if (conn != null &amp;&amp; !conn.isClosed()) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conn.close();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conn = null;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;} catch (SQLException e) {<br />&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;try {<br />&nbsp;&nbsp;&nbsp;&nbsp;if(reader!=null) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reader.close();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reader = null;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;} catch (IOException e) {<br />&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;} <br />&nbsp;} <br />} <br /><br />剩下的行集及离线结果集就看同学的链接吧，因为这两天是我没掌握好的! <br />袁彬的BLOG,没经过他同意,见谅啊<img alt="" src="/htmleditor/editor/images/emotion/07.gif" /><br /><a href="http://blog.csdn.net/ecaterina/archive/2006/12/06/1432161.aspx"><font color="#ff0000">http://blog.csdn.net/ecaterina/archive/2006/12/06/1432161.aspx</font></a> <br /><br /> ]]></description>
		<eb:creationDate>2006-12-13 16:05:46</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ JDBC第五天 ]]></title>
		<link>http://blog.tom.com/hoohey/article/1571.html</link>
		<description><![CDATA[ <BR><br /><br />时间：<font color="#ff0000">2006-12-04</font>&nbsp; <br />内容:1、SQL注入攻击<br />&nbsp;&nbsp;&nbsp;&nbsp;2、PreparedStatement用法，为什么要用它而不用Statement<br />&nbsp;&nbsp;&nbsp;&nbsp;3、ResultSet的三种属性，含义，用法 <br />&nbsp; <br /><font style="BACKGROUND-COLOR: #ffffff" color="#0000ff">■SQL注入</font>:初学者很容易犯的一个错误，就是在登陆的时候，一般验证是通过查询表select * from users where username =&nbsp;&nbsp; and password =&nbsp; 来查询，这样的话如果不做处理，很可能导致恶意登陆，即在第一个&nbsp;(用户)处加' or '1'='1' or '1'='1 或者在第二个&nbsp;(密码)处加 ' or '1'='1' ；<br />这就叫Sql注入,那么如何防止出现这种错误呢？下面写个程序来说明一下：<br />&nbsp;<br />import java.io.*;<br />import java.sql.*;<br />public class Demo{<br />&nbsp;public static void main(String[] args ) throws ClassNotFoundException{<br />&nbsp;&nbsp;Connection conn = null;<br />&nbsp;&nbsp;Statement stmt = null;<br />&nbsp;&nbsp;ResultSet rs = null;<br />&nbsp;&nbsp;String username = null;<br />&nbsp;&nbsp;String password = null;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;try {<br />&nbsp;&nbsp;&nbsp;System.out.println("请输入帐号：");<br />&nbsp;&nbsp;&nbsp;BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));<br />&nbsp;&nbsp;&nbsp;username = reader.readLine();<br />&nbsp;&nbsp;&nbsp;System.out.println("请输入密码：");<br />&nbsp;&nbsp;&nbsp;password = reader.readLine();<br />&nbsp;&nbsp;} catch (IOException e1) {<br />&nbsp;&nbsp;&nbsp;e1.printStackTrace();<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;Class.forName("com.mysql.jdbc.Driver");<br />&nbsp;&nbsp;try {<br />&nbsp;&nbsp;&nbsp;Class.forName("com.mysql.jdbc.Driver");<br />&nbsp;&nbsp;&nbsp;conn = DriverManager.getConnection("jdbc:mysql:///test&nbsp;user=root&amp;password=");<br />&nbsp;&nbsp;&nbsp;stmt = conn.createStatement();<br />&nbsp;&nbsp;&nbsp;String sql = "select * from users where username='"+username+"' and password='"+password+"'";<br />&nbsp;&nbsp;&nbsp;//String sql = "select * from user where name='" + username.replaceAll("'","''") + <br />&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"' and password='" + password.replaceAll("'","''") + "'";<br />&nbsp;&nbsp;&nbsp;rs = stmt.executeQuery(sql);<br />&nbsp;&nbsp;&nbsp;if (rs.next())<br />&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("登录成功!");<br />&nbsp;&nbsp;&nbsp;else <br />&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("失败！");<br />&nbsp;&nbsp;&nbsp;conn.close();<br />&nbsp;&nbsp;} catch (SQLException e) {<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;}<br />&nbsp;}<br />}<br />如果这段程序不做处理的话，就会导致SQL注入.但是可以用注解部分的那句sql，该句进行了转义，通过''来进行转义，它其实代表一个' <br />由此也导出<font color="#0000ff">PreparedStatement</font>，PreparedStatement 可以避免这种情况的产生，而且它还比Statement 有以下几个优点：<br />1、可以动态设参数<br />2、Statement是拿过SQL语句再来编译，如果执行很多行的话，同一条语句也要重复执行，消耗资源；而PreparedStatement相同的只执行一次，然后<br />等待参数的输入再执行。<br />3、参数传递,会自动转义，防止SQL注入攻击，可以根据数据类型过滤。<br /><font color="#0000ff">■</font>下面给出一个我自己写的完整的登陆程序，用<font color="#993366">PreparedStatement</font>实现的<br />public class PreparedStatementTestLogin { <br />&nbsp;public static void main(String[] args) {<br />&nbsp;&nbsp;Connection conn = null;<br />&nbsp;&nbsp;PreparedStatement stmt = null;<br />&nbsp;&nbsp;ResultSet rs = null;<br />&nbsp;&nbsp;String username = null;<br />&nbsp;&nbsp;String password = null;<br />&nbsp;&nbsp;BufferedReader reader = null;<br />&nbsp;&nbsp;byte[] buf=null;<br />&nbsp;&nbsp;int len=0;<br />&nbsp;&nbsp;buf = new byte[128];<br />&nbsp;&nbsp;reader = new BufferedReader(new InputStreamReader(System.in));<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;try {<br />&nbsp;&nbsp;&nbsp;System.out.println("输入您的用户名:");<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;len = System.in.read(buf);//计算读入的字符个数<br />&nbsp;&nbsp;&nbsp;username = new String(buf,0,len-System.getProperty("line.separator").length());//跨平台,因为Linux中只有＼<a href="file://r">r</a>没有＼<a href="file://n">n</a><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;System.out.println("输入您的密码:");<br />&nbsp;&nbsp;&nbsp;len = System.in.read(buf);//计算读入的字符个数<br />&nbsp;&nbsp;&nbsp;password = new String(buf,0,len-System.getProperty("line.separator").length());<br />&nbsp;&nbsp;} catch (IOException e1) {<br />&nbsp;&nbsp;&nbsp;// TODO Auto-generated catch block<br />&nbsp;&nbsp;&nbsp;e1.printStackTrace();<br />&nbsp;&nbsp;} <br />&nbsp;&nbsp;if(username.length()==0||password.length()==0){<br />&nbsp;&nbsp;&nbsp;System.out.println("姓名和密码不能为空");<br />&nbsp;&nbsp;&nbsp;System.exit(1);<br />&nbsp;&nbsp;}&nbsp;&nbsp;<br />&nbsp;&nbsp;try {<br />&nbsp;&nbsp;&nbsp;&nbsp;Class.forName("com.mysql.jdbc.Driver");<br />&nbsp;&nbsp;&nbsp;&nbsp;conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test&nbsp;user=root&amp;password=");<br />&nbsp;&nbsp;&nbsp;&nbsp;conn.setAutoCommit(false);<br />&nbsp;&nbsp;&nbsp;&nbsp;String sql = "select * from user where name=&nbsp; and password=&nbsp;";<br />&nbsp;&nbsp;&nbsp;&nbsp;stmt = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//上面这句定义了结果集的类型<br />&nbsp;&nbsp;&nbsp;&nbsp;stmt.setString(1,username);//将指定的参数(也就是1,就是第一个&nbsp;)用username的值代替<br />&nbsp;&nbsp;&nbsp;&nbsp;stmt.setString(2,password);<br />&nbsp;&nbsp;&nbsp;&nbsp;rs=stmt.executeQuery();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;if(rs.next()){<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("验证通过!");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("更改密码请按1并回车,增加用户请按2并回车");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Scanner in = new Scanner(System.in);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int num = in.nextInt();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(num==1){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("请输入密码：");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Scanner in2 = new Scanner(System.in);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String str = in2.nextLine();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rs.updateString("password",str);//注意类型<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rs.updateRow();//一定要这句，才会往数据库里更新，另外生成语句的时候PreparedStatement要设置结果集类型。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("密码更改成功!");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//输入新用户：<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(num==2){&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String newuser=null;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String newUserpw=null;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("请输入新用户名：");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newuser = reader.readLine();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("请输入新用户密码：");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newUserpw = reader.readLine();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} catch (IOException e) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//将游标移到可插入位置<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rs.moveToInsertRow();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//修改记录<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rs.updateString("name",newuser);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rs.updateString("password",newUserpw);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}else<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("用户名或者密码有误!");<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;conn.commit();<br />&nbsp;<br />&nbsp;&nbsp;&nbsp;} catch (ClassNotFoundException e) {<br />&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;}catch (SQLException e) {<br />&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;&nbsp;try {<br />&nbsp;&nbsp;&nbsp;&nbsp;conn.rollback();<br />&nbsp;&nbsp;&nbsp;} catch (SQLException e1) {<br />&nbsp;&nbsp;&nbsp;&nbsp;e1.printStackTrace();<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;finally{<br />&nbsp;&nbsp;&nbsp;try {<br />&nbsp;&nbsp;&nbsp;&nbsp;if(rs!=null){<br />&nbsp;&nbsp;&nbsp;&nbsp;rs.close();<br />&nbsp;&nbsp;&nbsp;&nbsp;rs=null;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;} catch (SQLException e) {<br />&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;try {<br />&nbsp;&nbsp;&nbsp;&nbsp;if(stmt!=null){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stmt.close();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stmt=null;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;} catch (SQLException e) {<br />&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;try {<br />&nbsp;&nbsp;&nbsp;&nbsp;if(conn!=null&amp;&amp;!conn.isClosed()){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conn.close();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conn=null;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;} catch (SQLException e) {<br />&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;return;<br />&nbsp;} <br />} <br />标准的写法就是这样的，注意finally中的几个关闭，这样才能将发生错误的可能减少到最低. <br /><font color="#0000ff">■结果集 ResultSet</font> .<br />结果集(ResultSet)有三个属性：类型、并发性、有效性。 <br />结果集(ResultSet)分三种类型<br />TYPE_FORWARD_ONLY: 游标仅仅可以向前移动<br />TYPE_SCROLL_INSENSITIVE: 游标可以前后移动并且可以循环移动，而且对底层数据库的变化是不敏感的，也就是说<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; 从数据库中取出结果集之后，如果这时别人修改了数据库，那么结果集是不变的<br />TYPE_SCROLL_SENSITIVE: 和上面对应，不同之处是如果别人更改了数据库，那么结果集也会发生相应的变化。 <br />对于可以任意移动指针的结果集(后两个类型)，可以用来移动指针的方法包括：<br />next和previous：<br />absolute和relative：参数可正可负 <br />afterLast、beforeFirst、last和first： <br />结果集的并发性共有两种，CONCUR_READ_ONLY的结果集是只读而不可更新的；<br />而CONCUR_UPDATABLE的结果集则是可以通过update方法进行更新的。 <br />结果集的有效性是指在调用了Connection接口的commit方法后，结果集是否自动关闭游标。<br />所以它只有两个可选值，即HOLD_CURSORS_OVER_COMMIT和CLOSE_CURSORS_AT_COMMIT。<br />前者表示调用commit方法之后，结果集不关闭；而后者则表示关闭结果集。 ]]></description>
		<eb:creationDate>2006-12-13 15:37:17</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ JDBC第四天 ]]></title>
		<link>http://blog.tom.com/hoohey/article/1569.html</link>
		<description><![CDATA[ <br />时间：<font color="#ff0000">2006-12-03</font> 内容：深拷贝/浅拷贝、深克隆/浅克隆 <br />&nbsp; <br />零碎知识：<br />1、基本数据类型(int,char,float,double,byte,short,long,boolean)所在的内存空间位于栈中。<br />2、只要是通过new操作创建出来的都是对象，对象位于堆中。<br />3、引用是对象的地址，位于栈中。<br />4、通过classA instanceof classB来判断A是否为B的实例，返回的结果是boolean型。<br />5、所有的类都是从Object继承而来，故所有的类都有equals方法，而最初Object的equals都只是比较地址，但是那些包装类(比如Integer、 <br />String等)SUN公司已经做了覆盖，所以他们是比较值的<br />6、多态：子类继承父类，父类的属性不会被覆盖,下面给出一个多态的例子:<br />&nbsp;class Father<br />&nbsp;{<br />&nbsp;&nbsp;int x = 2;<br />&nbsp;&nbsp;int method(){<br />&nbsp;&nbsp;&nbsp;return x;<br />&nbsp;&nbsp;}<br />&nbsp;} <br />&nbsp;public class Son extends Father<br />&nbsp;{<br />&nbsp;&nbsp;int x = 3 ;<br />&nbsp;&nbsp;int method(){<br />&nbsp;&nbsp;return x ;<br />&nbsp;&nbsp;} <br />&nbsp;&nbsp;public static void main(String[] args)<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;Father f = new Son();<br />&nbsp;&nbsp;System.out.println(f.x);<br />&nbsp;&nbsp;System.out.println(f.method());<br />&nbsp;&nbsp;}<br />&nbsp;} <br />结果为：2<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 <br /><font color="#ff0000">【深/浅拷贝】<br /></font>先写一个Person类 <br /><br />public class Person{<br />&nbsp;String name = null;<br />&nbsp;int idcard ;<br />&nbsp;public Person(){}<br />&nbsp;public Person(String name,int idcard){<br />&nbsp;&nbsp;this.name = name;<br />&nbsp;&nbsp;this.idcard= idcard;<br />&nbsp;&nbsp;<br />&nbsp;}&nbsp;<br />/*&nbsp;public boolean equals(Object obj) <br />&nbsp;{<br />&nbsp;&nbsp;boolean result = false;<br />&nbsp;&nbsp;if(obj instanceof Person)<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;Person p = (Person) obj;<br />&nbsp;&nbsp;&nbsp;if((p.getName()==this.getName())&amp;&amp;(p.getidcard()==this.getidcard()))<br />&nbsp;&nbsp;&nbsp;&nbsp; result = true;<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;return result;<br />&nbsp;}*/<br />&nbsp;public String getName() {<br />&nbsp;&nbsp;return name;<br />&nbsp;}<br />&nbsp;public void setName(String name) {<br />&nbsp;&nbsp;this.name = name;<br />&nbsp;}<br />&nbsp;public int getidcard() {<br />&nbsp;&nbsp;return idcard;<br />&nbsp;}<br />&nbsp;public void setidcard(int idcard) {<br />&nbsp;&nbsp;this.idcard = idcard;<br />&nbsp;}<br />/*&nbsp;public int hashCode() {<br />&nbsp;&nbsp;//默认情况下是return super.hashCode();<br />&nbsp;&nbsp;return new Integer(this.idcard).hashCode()+new String(this.name).hashCode();<br />&nbsp;} */ <br />} <br />}<br />再给出上面类的一个应用 <br />public class Test { <br />&nbsp;public static void main(String[] args) {<br />&nbsp;&nbsp;Person p1 = new Person("Hoo", 24);<br />&nbsp;&nbsp;Person p2 = new Person("Hey", 24);<br />&nbsp;&nbsp;Person p3 = new Person(new String("Gavin"), 28);<br />&nbsp;&nbsp;Person p4 = new Person(new String("King"), 28); <br />&nbsp;&nbsp;/**<br />&nbsp;&nbsp; * 下面浅拷贝，只是把p2的getName()的地址和getidcard()的地址拷贝给p1 那么它们肯定是指向相同的内容<br />&nbsp;&nbsp; */<br />&nbsp;&nbsp;p1.setName(p2.getName());<br />&nbsp;&nbsp;p1.setidcard(p2.getidcard()); <br />&nbsp;&nbsp;/**<br />&nbsp;&nbsp; * 下面深拷贝，把p4的getName()的值和getidcard()的值拷贝到另一个地方 然后将p3指向该地址<br />&nbsp;&nbsp; */<br />&nbsp;&nbsp;p3.setName(p4.getName());<br />&nbsp;&nbsp;p3.setidcard(p4.getidcard()); <br />&nbsp;&nbsp;System.out.println(p1.getName() == p2.getName()); // true<br />&nbsp;&nbsp;System.out.println(p3.getName() == p4.getName()); // true <br />&nbsp;&nbsp;System.out.println(p1 == p2);<br />&nbsp;&nbsp;System.out.println(p3 == p4);<br />&nbsp;&nbsp;/**<br />&nbsp;&nbsp; * 如果Person类覆盖了equals类，那么hashCode()也要覆盖,因为我们认为姓名和身份证号<br />&nbsp;&nbsp; * 相同那么就是同一个人，这样的话hashCode()应该相同.如果不覆盖这两个对象的hashCode肯定不一样。<br />&nbsp;&nbsp; * 但是hashCode()相同就不一定是同一个人,因为Name.hashCode()+Age.hashCode相等的话，不一定姓名和idcard一样<br />&nbsp;&nbsp; */<br />&nbsp;&nbsp;System.out.println(p1.hashCode());<br />&nbsp;&nbsp;System.out.println(p2.hashCode()); <br />&nbsp;} <br />}<br />重点:**如果对象相同(equals返回true)，那么要求hashCode返回相同，因为要往hashtable里面插；<br />&nbsp;&nbsp;&nbsp;&nbsp; **如果hashCode相同，不一定对象相同(即不一定equals方法返回true)；<br />&nbsp;&nbsp;&nbsp;&nbsp; **那些包装类SUN公司已经覆盖了equals方法，即完成了我们的覆盖操作<br />&nbsp;&nbsp;&nbsp;&nbsp; **学会覆盖equals和hashCode方法和理解什么情况下需要覆盖.<br /><font color="#ff0000">【克隆】:</font> <br />某个类要实现clone方法的话，必须实现cloneable()接口(是个空接口)，标明对象可以克隆，而且要覆盖父类(即Object)的clone方法，因为默 <br />认情况下clone方法是private的，要更改为public。<br />public class Person implements cloneable()<br />{<br />&nbsp;...<br />&nbsp;public Object clone() throws CloneNotSupportedException{<br />&nbsp;/*&nbsp;Person p = new Person(this.age,this.name) ;<br />&nbsp;&nbsp;return p ;*/<br />&nbsp;&nbsp;return super.clone();&nbsp; <br />&nbsp;}<br />}<br />Person p = new Person(32,"john");<br />try<br />{<br />&nbsp;Person p1 = (Person)p.clone();<br />&nbsp;System.out.println(p1.age==p.age);&nbsp; //true ;<br />&nbsp;System.out.println(p1.name==p.name); //true ;<br />&nbsp;System.out.println(p==p1);&nbsp; //false ;<br />&nbsp;//可见，即便是使用super.clone()方法还是实现的是浅克隆，对象的副本中的属性和主本中的属性<br />&nbsp;//其实还是一个地址。<br />}<br />catch(CloneNotSupportedException ex)<br />{<br />&nbsp;ex.printStackTrace();<br />}<br />注意：使用clone时，不能用其他类的clone方法，比如另一个类想用Person.clone()是会出错的 <br /><font color="#ff0000">【集合类】</font><br />分两类:Collection和Map<br />List和Set都继承了Collection<br />List：add(int index,Object element)：如果往第三个位置插入一个元素的话，其他元素顺序<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 往下移动，List是有索引的，也就是说它是有序的集合<br />&nbsp;&nbsp;&nbsp; List 有分ArrayList和LinList,他们之间的区别是前者是一个数组list后者是链表list，数组有空间上的限制(数组溢出)而链表没有，但 <br />是数组的读取速度要高于链表.<br />&nbsp;ArrayList().add(pos,obj);//存储的是Obj,pos是在数组中的位置<br />&nbsp;ArrayList().get(pos); //可以通过get来取的第pos个位置上的Obj <br />Set：List有顺序但不唯一,Set无序但唯一(不包含重复元素)，里面最多包含一个null值<br />&nbsp; &nbsp;由于Set没有get方法(因为它无序),所以必须通过迭代器来遍历所有元素 <br /><br /><font color="#ff0000">【迭代器】</font> Iterator&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />Iterator it = list.iterator();<br />while(it.hasNext)&nbsp; //表示有没有下一个,有的话执行里面的<br />{<br />&nbsp;Object obj = it.next();<br />&nbsp;if(obj instanceof Person){}<br />&nbsp;else }<br />&nbsp;&nbsp;System.out.println(obj);<br />&nbsp;}<br />}<br />所有的对象都有Iterator ]]></description>
		<eb:creationDate>2006-12-10 13:32:52</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ JDBC第三天 ]]></title>
		<link>http://blog.tom.com/hoohey/article/1568.html</link>
		<description><![CDATA[ <BR>时间:<font color="#ff0000">2006-12-02</font> 内容:SqlServer2005<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;今天兼职袁SIR主讲SqlServer,其实我SqlServer挺熟的,毕竟用了好几个月呢,可是听了他讲才发现我只是懂点皮毛,分页是我所不知道的,最高兴的一点是,存储过程我终于知道怎么写了,原来这么简单....<BR>来看一个存储过程先<BR>if object_id('hoohey') is not null&nbsp;&nbsp;&nbsp; //先判断是否存在<br />&nbsp;&nbsp; drop proc hoohey<br />go<BR><br />create proc hoohey(@Player varchar(20))//其中()里的是参数,注意要@<br />as<br />begin<br />&nbsp; declare @MaxScore&nbsp; float,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; @MinScore&nbsp; float,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; @MaxJudge&nbsp; varchar(20),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; @MinJudge&nbsp; varchar(20)<br />select @MaxScore=Max(Score),@MinScore=min(Score) from Grade where <a href="mailto:Player=@Player">Player=@Player</a><br />select @MaxJudge=Judge from Grade where <a href="mailto:Score=@MaxScore">Score=@MaxScore</a> and <a href="mailto:Player=@Player">Player=@Player</a><br />select @MinJudge=Judge from Grade where <a href="mailto:Score=@MinScore">Score=@MinScore</a> and <a href="mailto:Player=@Player">Player=@Player</a><br />select (sum(Score)-@MaxScore-@MinScore)/(count(*)-2) as AverScore,@MaxScore,@MinScore,@MaxJudge,@MinJudge from Grade where <a href="mailto:Player=@Player">Player=@Player</a><BR>end<br /><BR>exec hoohey //执行存储过程<BR>&nbsp;<BR><font color="#ff00ff">例子</font>：自动生成身份证号(给两个参数一个地区,一个日期)：<BR>create table Person //建表<br />{<br />&nbsp;id int identity(1,1) primary key,<br />&nbsp;CardNo varchar(18),<br />&nbsp;Name nvarchar(10)<br />}<br />insert into values(CardNo,Name) values('422423197504124559','袁龙友')<br />插入袁SIR的身份证号码<br />select * from Person<BR>注意：422423197504124559去掉前6位和后4位，得到的是19750412，这就是袁老师的<br />出生日期，存储过程要求生成一个身份证号码，前6位保持不变，而且后4位要加上1，<br />中间的是生日。<BR>这个存储过程给了前6位号，中间8位号，我们只要顾及最后4位号就可以了。<br />if object_id('GenNewCardNo') is not null<br />&nbsp; drop proc GenNewCardNo<br />go<BR>create proc GenNewCardNo(@RegionCode varchar(6),@Birthday varchar(8))<br />as <br />begin<br />&nbsp;&nbsp; declare @CardNo varchar(18)<br />&nbsp;&nbsp; <br />&nbsp;&nbsp; select @CardNo=@RegionCode+@Birthday+replace(str(max(Right(CardNo,4))+1,4),' ','0') <br />&nbsp;&nbsp;&nbsp;&nbsp; from Person <font color="#0000ff">where </font>left(CardNo,4) = @RegionCode+@Birthday<br />&nbsp;<br />&nbsp;insert into Person(CardNo) values(@CardNo)<BR>end<BR>exec GenNewCardNo '422423','19750412'<BR>&nbsp;<BR>如果你是符合条件的第一个人的话，那么<font color="#0000ff">where</font>条件还不成立呢，因为还没有满足条件的记录呢！那么如果这样的话刚才的存储过程就无法得到记录了！上面的存储过程无法处理当天第一个出生的人！<BR>可以设置一个号码，如果真的是空的话，给它置为1。<br />begin<br />&nbsp;&nbsp; declare @CardNo varchar(18)<br />&nbsp;&nbsp;&nbsp;@Num int<br />&nbsp;select @Num = max(right(CardNo,4))+1 from Person where left(CardNo,4) = @RegionCode+@Birthday<br />&nbsp;if @Num is null //如果确实是当天第一个出生的人，那么肯定数据库中没有相应的身份证记录，那么@Num必然为空！<br />&nbsp;&nbsp;set @Num=1<br />&nbsp;<br />&nbsp;&nbsp; select @CardNo=@RegionCode+@Birthday+replace(str(@Num,4),' ','0') <br />&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;<br />&nbsp;insert into Person(CardNo) values(@CardNo)<br />&nbsp;select @CardNo<br />end<BR>exec GenNewCardNo '422421','19750412'<BR>&nbsp;<BR>要知道<font style="BACKGROUND-COLOR: #ffffff" color="#ff00ff">索引重建</font>的意义,因为如果建了索引的话,每次插入数据,索引要变动一下,时间长了,更新记录的时候会变的速度很慢,因为记录要一条条往后移,所以要重建索引.一般情况下,表不多,字段文本比较大,经常修改这样的列不该建索引..<BR>&nbsp;<BR>&nbsp;<BR>分页:<BR>select top n column from table //选前几条记录比如n=10就是前10条<BR>最好用,但也有局限性(只满足只有一条主键的表):<BR>declare @ID int<BR>select top 10 @ID=ID from table<BR>//取第一页的前10行，最后的第10行ID数值被赋给了@ID,但是这对主键的要求比较高，要求必须升序且不跳数。<BR>print @ID //这时@ID=10<BR>select top 10 * from table where ID&gt;@ID<BR>&nbsp;<BR>&nbsp; ]]></description>
		<eb:creationDate>2006-12-06 19:55:55</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ JDBC第二天 ]]></title>
		<link>http://blog.tom.com/hoohey/article/1567.html</link>
		<description><![CDATA[ <BR>时间:<font color="#ff0000">2006-12-01</font> 内容:Statement及DataSource<BR>同期同学袁彬(思路很清晰的一个小伙子)写的很详细,改天再细细拜读一下:<BR><a href="http://blog.csdn.net/ecaterina/archive/2006/12/05/1430787.aspx">http://blog.csdn.net/ecaterina/archive/2006/12/05/1430787.aspx</a><BR>&nbsp;<BR>import java.sql.Connection;<br />import java.sql.DatabaseMetaData;<br />import java.sql.DriverManager;<br />import java.sql.ResultSet;<br />import java.sql.Statement;<BR>public class IsolationDemo {<BR>&nbsp;<br />&nbsp;public static void main(String[] args) {<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;Connection conn = null;<br />&nbsp;&nbsp;Statement stmt = null;<br />&nbsp;&nbsp;ResultSet rs = null;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;try {<br />&nbsp;&nbsp;&nbsp;Class.forName("oracle.jdbc.OracleDriver");<br />&nbsp;&nbsp;&nbsp;conn = DriverManager.getConnection ("jdbc:oracle:thin:hr/hr@localhost:1521:orcl");<br />&nbsp;&nbsp;&nbsp;<font color="#3366ff">DatabaseMetaData dmd = conn.getMetaData();<br />&nbsp;&nbsp;&nbsp;if(dmd.supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE))</font> {<br />&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Transaction Isolation Level setted!");<br />&nbsp;&nbsp;&nbsp;&nbsp;conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;conn.setAutoCommit(false);<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;stmt = conn.createStatement();<br />&nbsp;&nbsp;&nbsp;rs = stmt.executeQuery("select salary from employees where employee_id=200");//stmt.executeQuery("select count(*) from employees");<br />&nbsp;&nbsp;&nbsp;if(rs.next()) System.out.println(rs.getString(1));<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;Thread.sleep(15000);//停滞15秒,然后另一个进程更新数据库<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;rs = stmt.executeQuery("select salary from employees where employee_id=200");//stmt.executeQuery("select count(*) from employees");<br />&nbsp;&nbsp;&nbsp;if(rs.next()) System.out.println(rs.getString(1));<br />&nbsp;&nbsp;&nbsp;conn.commit();<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;} catch (ClassNotFoundException e) {<br />&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;} catch (Exception e) {<br />&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;}<br />&nbsp;}<BR>}<br />这段代码的目的是演示防止脏读和不可重复读而写的,注意蓝色代码,于是就引出:<BR><font color="#ff0000">★</font>事务的隔离级别<br />（1）有几种事务隔离级别。//有5种, JDK1.5的connection中Field Summary<br />&nbsp;TRANSACTION_NONE&nbsp; //<font color="#ff00ff">不支持事务</font>。<br />&nbsp;TRANSACTION_READ_COMMITTED&nbsp; //<font color="#ff00ff">阻止脏读，但不能阻止幻读和不可重复读</font><br />&nbsp;TRANSACTION_READ_UNCOMMITTED<br />&nbsp;TRANSACTION_REPEATABLE_READ&nbsp; //<font color="#ff00ff">能防止不可重复读和脏读<br /></font>&nbsp;TRANSACTION_SERIALIZABLE //<font color="#ff00ff">能防止上述的三种</font><BR>（2）事务隔离级别较低时可能会导致的脏读、不可重复读和幻读分别是什么含义<br />&nbsp;脏读：一个事务读到另一个事务的中间状态,比如读到更新过程中的数据<br />&nbsp;幻读：读的过程中有人加了记录,记录数目增加了<br />&nbsp;不可重复读：读的过程中有人更改了记录,记录被更新过,但数目没加<br />（3）知道如何更改驱动程序的事务隔离级别。<BR>&nbsp;<BR>1、事务边界<br />（1）默认情况下，JDBC每执行一条DML语句就提交一次，即一句话就是一个事务。<br />（2）如果需更改事务边界，需调用<font color="#ff0000">Connection.setAutoCommit(false);</font>来取消自动提交。然后在事务结束的地方调用Connection.commit()提交事务，在异常代码块加rollback()回滚事务。<br />2、保存点<br />（1）创建保存点，Connection.setSavepoint()生成保存<br />（2）回滚到保存点，Connection.rollback(Savepoint);<br />e.g:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SavePoint sp = conn.setSavePoint("first");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conn.rollback(sp);<BR>&nbsp; ]]></description>
		<eb:creationDate>2006-12-06 19:24:21</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
</channel>
</rss>