??xml version="1.0" encoding="utf-8" standalone="yes"?>黄网站在线观看,日本在线成人一区二区,国产精品911http://www.aygfsteel.com/hezhi/category/49018.htmlzh-cnWed, 31 Aug 2011 20:15:14 GMTWed, 31 Aug 2011 20:15:14 GMT60ORACLE忘记SYS密码的解军_?【{?/title><link>http://www.aygfsteel.com/hezhi/articles/357050.html</link><dc:creator>何智</dc:creator><author>何智</author><pubDate>Mon, 22 Aug 2011 07:55:00 GMT</pubDate><guid>http://www.aygfsteel.com/hezhi/articles/357050.html</guid><wfw:comment>http://www.aygfsteel.com/hezhi/comments/357050.html</wfw:comment><comments>http://www.aygfsteel.com/hezhi/articles/357050.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/hezhi/comments/commentRss/357050.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/hezhi/services/trackbacks/357050.html</trackback:ping><description><![CDATA[<div style="layout-grid: 15.6pt none" class="Section0"> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">ORACLE <font face="宋体">忘记</font><font face="Times New Roman">SYS</font><font face="宋体">密码</font><font face="Times New Roman">2008-06-20 16:56</font><font face="宋体">今天?/font><font face="Times New Roman">SYS</font><font face="宋体">w䆾q接数据库时出错Q权限不I不知道是无意中修改了</font><font face="Times New Roman">SYS</font><font face="宋体">的密码还是怎么回事。但q好</font><font face="Times New Roman">SYSTEM</font><font face="宋体">的密码没有忘记?/font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">下面是我的修Ҏ(gu)骤:</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">1<font face="宋体">。以</font><font face="Times New Roman">SYSTEM</font><font face="宋体">w䆾q去</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">2<font face="宋体">?/font><font face="Times New Roman">SQL> show parameter password;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">NAME                                 TYPE        VALUE</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">------------------------------------ ----------- ------------------------------</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'">remote_login_passwordfile            string      EXCLUSIVE</span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">我的<font face="Times New Roman">VALUE</font><font face="宋体">?/font><font face="Times New Roman">EXCLUSIVE</font><font face="宋体">Q如果你的结果是其他Q请参看下面的信息。当然你也可以用</font><font face="Times New Roman">SQL>alter system set remote_login_passwordfile='exclusive' scope=spfile; </font><font face="宋体">命o修改</font><font face="Times New Roman">remote_login_passwordfile</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">3<font face="宋体">?/font><font face="Times New Roman">CMD </font><font face="宋体">q入命o行,输入如下命o </font><font face="Times New Roman">orapwd file=C:\oracle\product\10.2.0\db_3\database\pwdorcl1.ora password=test</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">注意 <font face="Times New Roman">file=C:\oracle\product\10.2.0\db_3\database\pwdorcl1.ora</font><font face="宋体">Q?/font><font face="Times New Roman">pwdorcl1.ora</font><font face="宋体">是你的密码文件名字,命名规则?/font><font face="Times New Roman">pwdxxx.ora</font><font face="宋体">Q?/font><font face="Times New Roman">xxx</font><font face="宋体">是你的数据库名,不是实例名。然后此文g得放在固定目录下Q?/font><font face="Times New Roman">9i</font><font face="宋体">Q?/font><font face="Times New Roman">10i</font><font face="宋体">的固定目录ؓ</font><font face="Times New Roman">oracle_home\database</font><font face="宋体">目录Q如果你的目录下原先已存在名字相同的文gQ事先得删掉</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">4<font face="宋体">。现在就可以?/font><font face="Times New Roman">SYS</font><font face="宋体">的n份登录进M</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">具体关于<font face="Times New Roman">SYS</font><font face="宋体">密码及参?/font><font face="Times New Roman">remote_login_passwordfile </font><font face="宋体">的信息请参考如下:</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">Oracle<font face="宋体">中,假如用户要以Ҏ(gu)用户w䆾d</font><font face="Times New Roman">Oracle</font><font face="宋体">Q具体有两种w䆾验证的方法: </font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">Q?font face="Times New Roman">1</font><font face="宋体">Q用与操作pȝ集成的n份验?nbsp;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">Q?font face="Times New Roman">2</font><font face="宋体">Q?/font><font face="Times New Roman">Oracle</font><font face="宋体">数据库的密码文gq行w䆾验证?nbsp;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">因此Q管理好密码文gQ对于控制授权用户从q端或本机登?font face="Times New Roman">Oracle</font><font face="宋体">数据库系l,执行数据库管理工作,都具有特别重要的意义</font><font face="Times New Roman">.</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">Oracle<font face="宋体">数据库的密码文g存放有超U用?/font><font face="Times New Roman">INTERNAL</font><font face="宋体">Q?/font><font face="Times New Roman">SYS</font><font face="宋体">的口令及其他Ҏ(gu)用户的用户名Q口令,一般存攑֜</font><font face="Times New Roman">ORACLE_HOME</font><font face="宋体">Q?/font><font face="Times New Roman">DATABASE</font><font face="宋体">的目录下?/font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">一?nbsp;密码文g的创建:</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">在?font face="Times New Roman">Oracle Instance Manager</font><font face="宋体">创徏一数据库实例的时侯Q在</font><font face="Times New Roman">ORACLE_HOME</font><font face="宋体">Q?/font><font face="Times New Roman">DATABASE</font><font face="宋体">目录下还自动创徏了一个与之对应的密码文gQ文件名?/font><font face="Times New Roman">PWDSID.ORA</font><font face="宋体">Q其?/font><font face="Times New Roman">SID</font><font face="宋体">代表相应?/font><font face="Times New Roman">Oracle</font><font face="宋体">数据库系l标识符。此密码文g是进行初始数据库理工作的基。在此之后,理员也可以Ҏ(gu)需要,使用工具</font><font face="Times New Roman">ORAPWD.EXE</font><font face="宋体">手工创徏密码文gQ命令格式如下: </font><font face="Times New Roman">c:\ ORAPWD FILE=< FILENAME></font><font face="宋体"> </font><font face="Times New Roman">PASSWORD =<PASSWORD> ENTRIES=<MAX_USERS></font></span><span style="font-family: 'Times New Roman'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">各命令参数的含义为:</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">FILENAME<font face="宋体">Q密码文件名Q?/font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">PASSWORD<font face="宋体">Q设|?/font><font face="Times New Roman">INTERNAL</font><font face="宋体">Q?/font><font face="Times New Roman">SYS</font><font face="宋体">帐号的口令;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">MAX_USERS<font face="宋体">Q密码文件中可以存放的最大用hQ对应于允许?/font><font face="Times New Roman">SYSDBA</font><font face="宋体">Q?/font><font face="Times New Roman">SYSOPER</font><font face="宋体">权限d数据库的最大用h。由于在以后的维护中Q若用户数超Z此限Ӟ则需要重建密码文Ӟ所以此参数可以Ҏ(gu)需要设|得大一些?/font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">有了密码文g之后Q需要设|初始化参数<font face="Times New Roman">REMOTE_LOGIN_PASSWORDFILE</font><font face="宋体">来控制密码文件的使用状态?nbsp;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">二?nbsp;讄初始化参?font face="Times New Roman">REMOTE_LOGIN_PASSWORDFILE</font><font face="宋体">Q?nbsp;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">?font face="Times New Roman">Oracle</font><font face="宋体">数据库实例的初始化参数文件中Q此参数控制着密码文g的用及其状态。它可以有以下几个选项Q?nbsp;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">NONE<font face="宋体">Q指C?/font><font face="Times New Roman">Oracle</font><font face="宋体">pȝ不用密码文ӞҎ(gu)用户的登录通过操作pȝq行w䆾验证Q?nbsp;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">EXCLUSIVE<font face="宋体">Q指C只有一个数据库实例可以使用此密码文件。只有在此设|下的密码文件可以包含有?/font><font face="Times New Roman">INTERNAL</font><font face="宋体">Q?/font><font face="Times New Roman">SYS</font><font face="宋体">以外的用户信息,卛_许将pȝ权限</font><font face="Times New Roman">SYSOPER</font><font face="宋体">Q?/font><font face="Times New Roman">SYSDBA</font><font face="宋体">授予?/font><font face="Times New Roman">INTERNAL</font><font face="宋体">Q?/font><font face="Times New Roman">SYS</font><font face="宋体">以外的其他用戗?nbsp;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">SHARED<font face="宋体">Q指C可有多个数据库实例可以使用此密码文件。在此设|下只有</font><font face="Times New Roman">INTERNAL</font><font face="宋体">Q?/font><font face="Times New Roman">SYS</font><font face="宋体">帐号能被密码文g识别Q即使文件中存有其他用户的信息,也不允许他们?/font><font face="Times New Roman">SYSOPER</font><font face="宋体">Q?/font><font face="Times New Roman">SYSDBA</font><font face="宋体">的权限登录。此讄为缺省倹{?nbsp;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">?font face="Times New Roman">REMOTE_LOGIN_PASSWORDFILE</font><font face="宋体">参数讄?/font><font face="Times New Roman">EXCLUSIVE</font><font face="宋体">?/font><font face="Times New Roman">SHARED</font><font face="宋体">情况下,</font><font face="Times New Roman">Oracle</font><font face="宋体">pȝ搜烦密码文g的次序ؓQ在pȝ注册库中查找</font><font face="Times New Roman">ORA_SID_PWFILE</font><font face="宋体">参数|它ؓ密码文g的全路径名)Q若未找刎ͼ则查?/font><font face="Times New Roman">ORA_PWFILE</font><font face="宋体">参数|若仍未找刎ͼ则用缺省?/font><font face="Times New Roman">ORACLE_HOME</font><font face="宋体">Q?/font><font face="Times New Roman">DATABASE</font><font face="宋体">Q?/font><font face="Times New Roman">PWDSID.ORA</font><font face="宋体">Q其中的</font><font face="Times New Roman">SID</font><font face="宋体">代表相应?/font><font face="Times New Roman">Oracle</font><font face="宋体">数据库系l标识符?nbsp;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">三?nbsp;向密码文件中增加、删除用P </span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">当初始化参数<font face="Times New Roman">REMOTE_LOGIN_PASSWORDFILE</font><font face="宋体">讄?/font><font face="Times New Roman">EXCLUSIVE</font><font face="宋体">Ӟpȝ允许?/font><font face="Times New Roman">INTERNAL</font><font face="宋体">Q?/font><font face="Times New Roman">SYS</font><font face="宋体">以外的其他用户以理员n份从q端或本机登录到</font><font face="Times New Roman">Oracle</font><font face="宋体">数据库系l,执行数据库管理工作;q些用户名必d在于密码文g中,pȝ才能识别他们。由于不是在创建数据库实例时自动创建的密码文gQ还是用工?/font><font face="Times New Roman">ORAPWD.EXE</font><font face="宋体">手工创徏的密码文Ӟ都只包含</font><font face="Times New Roman">INTERNAL</font><font face="宋体">Q?/font><font face="Times New Roman">SYS</font><font face="宋体">用户的信息;为此Q在实际操作中,可能需要向密码文gd或删除其他用户帐受?nbsp;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">׃仅被授予<font face="Times New Roman">SYSOPER</font><font face="宋体">Q?/font><font face="Times New Roman">SYSDBA</font><font face="宋体">pȝ权限的用h存在于密码文件中Q所以当向某一用户授予或收?/font><font face="Times New Roman">SYSOPER</font><font face="宋体">Q?/font><font face="Times New Roman">SYSDBA</font><font face="宋体">pȝ权限Ӟ他们的帐号也相应地被加入到密码文g或从密码文g中删除。由此,向密码文件中增加或删除某一用户Q实际上也就是对某一用户授予或收?/font><font face="Times New Roman">SYSOPER</font><font face="宋体">Q?/font><font face="Times New Roman">SYSDBA</font><font face="宋体">pȝ权限?nbsp;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">要进行此Ҏ(gu)权操作,需使用<font face="Times New Roman">SYSDBA</font><font face="宋体">权限Q或</font><font face="Times New Roman">INTERNAL</font><font face="宋体">帐号Q连入数据库Q且初始化参?/font><font face="Times New Roman">REMOTE_LOGIN_PASSWORDFILE</font><font face="宋体">的设|必Mؓ</font><font face="Times New Roman">EXCLUSIVE.</font><font face="宋体">具体操作步骤如下Q?nbsp;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">创徏相应的密码文Ӟ </span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">讄初始化参?font face="Times New Roman">REMOTE_LOGIN_PASSWORDFILE</font><font face="宋体">Q?/font><font face="Times New Roman">EXCLUSIVE</font><font face="宋体">Q?nbsp;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">使用<font face="Times New Roman">SYSDBA</font><font face="宋体">权限dQ?nbsp;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">CONNECT<font face="宋体"> </font><font face="Times New Roman">SYS</font><font face="宋体">Q?/font><font face="Times New Roman">internal_user_passsword</font><font face="宋体"> </font><font face="Times New Roman">AS</font><font face="宋体"> </font><font face="Times New Roman">SYSDBA</font><font face="宋体">Q?nbsp;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">启动数据库实例ƈ打开数据库; </span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">创徏相应用户帐号Q对其授权(包括<font face="Times New Roman">SYSOPER</font><font face="宋体">?/font><font face="Times New Roman">SYSDBA</font><font face="宋体">Q: </font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">授予权限Q?font face="Times New Roman">GRANT</font><font face="宋体"> </font><font face="Times New Roman">SYSDBA</font><font face="宋体"> </font><font face="Times New Roman">TO</font><font face="宋体"> </font><font face="Times New Roman">user_name</font><font face="宋体">Q?nbsp;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">收回权限Q?font face="Times New Roman">REVOKE</font><font face="宋体"> </font><font face="Times New Roman">SYSDBA</font><font face="宋体"> </font><font face="Times New Roman">FROM</font><font face="宋体"> </font><font face="Times New Roman">user_name</font><font face="宋体">Q?nbsp;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">现在q些用户可以以管理员w䆾d数据库系l了Q?nbsp;</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">四?nbsp;使用密码文gdQ?nbsp;</span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">有了密码文g后,用户可以用密码文件以<font face="Times New Roman">SYSOPER</font><font face="宋体">Q?/font><font face="Times New Roman">SYSDBA</font><font face="宋体">权限d</font><font face="Times New Roman">Oracle</font><font face="宋体">数据库实例了Q注意初始化参数</font><font face="Times New Roman">REMOTE_LOGIN_PASSWORDFILE</font><font face="宋体">应设|ؓ</font><font face="Times New Roman">EXCLUSIVE</font><font face="宋体">?/font><font face="Times New Roman">SHARED.</font><font face="宋体">M用户?/font><font face="Times New Roman">SYSOPER</font><font face="宋体">Q?/font><font face="Times New Roman">SYSDBA</font><font face="宋体">的权限登录后Q将位于</font><font face="Times New Roman">SYS</font><font face="宋体">用户?/font><font face="Times New Roman">Schema</font><font face="宋体">之下Q以下ؓ两个d的例子:</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">1. <font face="宋体">以管理员w䆾dQ?/font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">假设用户<font face="Times New Roman">scott</font><font face="宋体">已被授予</font><font face="Times New Roman">SYSDBA</font><font face="宋体">权限Q则他可以用以下命令登录:</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">CONNECT<font face="宋体"> </font><font face="Times New Roman">scott</font><font face="宋体">Q?/font><font face="Times New Roman">tiger</font><font face="宋体"> </font><font face="Times New Roman">AS</font><font face="宋体"> </font><font face="Times New Roman">SYSDBA</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">2. <font face="宋体">?/font><font face="Times New Roman">INTERNAL</font><font face="宋体">w䆾dQ?/font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">CONNECT<font face="宋体"> </font><font face="Times New Roman">INTERNAL</font><font face="宋体">Q?/font><font face="Times New Roman">INTERNAL_PASSWORD</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">五、密码文件的l护Q?/span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">1. <font face="宋体">查看密码文g中的成员Q?/font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">可以通过查询视图<font face="Times New Roman">V$PWFILE_USERS</font><font face="宋体">来获取拥?/font><font face="Times New Roman">SYSOPER</font><font face="宋体">Q?/font><font face="Times New Roman">SYSDBA</font><font face="宋体">pȝ权限的用L信息Q表?/font><font face="Times New Roman">SYSOPER</font><font face="宋体">Q?/font><font face="Times New Roman">SYSDBA</font><font face="宋体">列的取?/font><font face="Times New Roman">TRUE</font><font face="宋体">Q?/font><font face="Times New Roman">FALSE</font><font face="宋体">表示此用h否拥有相应的权限。这些用户也是相应地存在于密码文g中的成员?/font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">2. <font face="宋体">扩展密码文g的用h量:</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">当向密码文gd的帐h目超q创建密码文件时所定的限制Q即<font face="Times New Roman">ORAPWD.EXE</font><font face="宋体">工具?/font><font face="Times New Roman">MAX_USERS</font><font face="宋体">参数Q时Qؓ扩展密码文g的用h限制Q需重徏密码文gQ具体步骤如下:</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">Q?font face="Times New Roman">a</font><font face="宋体">Q?nbsp;查询视图</font><font face="Times New Roman">V$PWFILE_USERS</font><font face="宋体">Q记录下拥有</font><font face="Times New Roman">SYSOPER</font><font face="宋体">Q?/font><font face="Times New Roman">SYSDBA</font><font face="宋体">pȝ权限的用户信息;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">Q?font face="Times New Roman">b</font><font face="宋体">Q关闭数据库Q?/font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">Q?font face="Times New Roman">c</font><font face="宋体">Q?nbsp;删除密码文gQ?/font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">Q?font face="Times New Roman">d</font><font face="宋体">Q?nbsp;?/font><font face="Times New Roman">ORAPWD.EXE</font><font face="宋体">新徏一密码文gQ?/font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">Q?font face="Times New Roman">e</font><font face="宋体">Q?nbsp;步?/font><font face="Times New Roman">a</font><font face="宋体">中获取的用户d到密码文件中?/font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">3. <font face="宋体">修改密码文g的状态:</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"> 密码文g的状态信息存放于此文件中Q当它被创徏Ӟ它的~省状态ؓ<font face="Times New Roman">SHARED.</font><font face="宋体">可以通过改变初始化参?/font><font face="Times New Roman">REMOTE_LOGIN_PASSWORDFILE</font><font face="宋体">的设|改变密码文件的状态。当启动数据库事例时Q?/font><font face="Times New Roman">Oracle</font><font face="宋体">pȝ从初始化参数文g中读?/font><font face="Times New Roman">REMOTE_LOGIN_PASSWORDFILE</font><font face="宋体">参数的设|;当加载数据库Ӟpȝ此参数与口令文件的状态进行比较,如果不同Q则更新密码文g的状态。若计划允许从多台客h上启动数据库实例Q由于各客户Z必须有初始化参数文gQ所以应保各客h上的初始化参数文件的一致性,以避免意外地改变了密码文件的状态,造成数据库登陆的p|?nbsp;</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">4. <font face="宋体">修改密码文g的存储位|:</font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">密码文g的存放位|可以根据需要进行移动,但作此修改后Q应相应修改pȝ注册库有x向密码文件存放位|的参数或环境变量的讄?/span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">5. <font face="宋体">删除密码文gQ?/font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p> <p style="text-align: left; margin-top: 0pt; margin-bottom: 0pt" class="p0"><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'">在删除密码文件前Q应保当前q行的各数据库实例的初始化参?font face="Times New Roman">REMOTE_LOGIN_PASSWORDFILE</font><font face="宋体">皆设|ؓ</font><font face="Times New Roman">NONE.</font><font face="宋体">在删除密码文件后Q?nbsp;假如你想要以理员n份连入数据库的话Q就必须使用操作pȝ验证的方法进行登录?/font></span><span style="font-family: '宋体'; font-size: 10.5pt; mso-spacerun: 'yes'"><o:p></o:p></span></p></div><!--EndFragment--><img src ="http://www.aygfsteel.com/hezhi/aggbug/357050.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/hezhi/" target="_blank">何智</a> 2011-08-22 15:55 <a href="http://www.aygfsteel.com/hezhi/articles/357050.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java反射l典实例 Java Reflection Cookbook (初) http://www.aygfsteel.com/hezhi/articles/354144.html何智何智Tue, 12 Jul 2011 02:27:00 GMThttp://www.aygfsteel.com/hezhi/articles/354144.htmlhttp://www.aygfsteel.com/hezhi/comments/354144.htmlhttp://www.aygfsteel.com/hezhi/articles/354144.html#Feedback0http://www.aygfsteel.com/hezhi/comments/commentRss/354144.htmlhttp://www.aygfsteel.com/hezhi/services/trackbacks/354144.htmlJava提供了一套机制来动态执行方法和构造方法,以及数组操作{,q套机制叫——反射。反机制是如今很多行框架的实现基Q其中包括Spring、Hibernate{。原理性的问题不是本文的重点,接下来让我们在实例中学习q套_ֽ的机制?br />
1. 得到某个对象的属?br />
1 public Object getProperty(Object owner, String fieldName) throws Exception {
2     Class ownerClass = owner.getClass();
3 
4     Field field = ownerClass.getField(fieldName);
5 
6     Object property = field.get(owner);
7 
8     return property;
9 }

Class ownerClass = owner.getClass()Q得到该对象的Class?br />
Field field = ownerClass.getField(fieldName)Q通过Class得到cd明的属性?br />
Object property = field.get(owner)Q通过对象得到该属性的实例Q如果这个属性是非公有的Q这里会报IllegalAccessException?br />


2. 得到某个cȝ静态属?br />
 1 public Object getStaticProperty(String className, String fieldName)
 2             throws Exception {
 3     Class ownerClass = Class.forName(className);
 4 
 5     Field field = ownerClass.getField(fieldName);
 6 
 7     Object property = field.get(ownerClass);
 8 
 9     return property;
10 }


Class ownerClass = Class.forName(className) Q首先得到这个类的Class?br />
Field field = ownerClass.getField(fieldName)Q和上面一P通过Class得到cd明的属性?br />
Object property = field.get(ownerClass) Q这里和上面有些不同Q因属性是静态的Q所以直接从cȝClass里取?br />

3. 执行某对象的Ҏ(gu)

 1 public Object invokeMethod(Object owner, String methodName, Object[] args) throws Exception {
 2 
 3     Class ownerClass = owner.getClass();
 4 
 5     Class[] argsClass = new Class[args.length];
 6 
 7     for (int i = 0, j = args.length; i < j; i++) {
 8         argsClass[i] = args[i].getClass();
 9     }
10 
11     Method method = ownerClass.getMethod(methodName, argsClass);
12 
13     return method.invoke(owner, args);
14 }

Class owner_class = owner.getClass() Q首先还是必d到这个对象的Class?br />
5?行:配置参数的Class数组Q作为寻找Method的条件?br />
Method method = ownerClass.getMethod(methodName, argsClass)Q通过Method名和参数的Class数组得到要执行的Method?br />
method.invoke(owner, args)Q执行该MethodQinvokeҎ(gu)的参数是执行q个Ҏ(gu)的对象,和参数数l。返回值是ObjectQ也既是该方法的q回倹{?br />

4. 执行某个cȝ静态方?br />
 1 public Object invokeStaticMethod(String className, String methodName,
 2             Object[] args) throws Exception {
 3     Class ownerClass = Class.forName(className);
 4 
 5     Class[] argsClass = new Class[args.length];
 6 
 7     for (int i = 0, j = args.length; i < j; i++) {
 8         argsClass[i] = args[i].getClass();
 9     }
10 
11     Method method = ownerClass.getMethod(methodName, argsClass);
12 
13     return method.invoke(null, args);
14 }


基本的原理和实例3相同Q不同点是最后一行,invoke的一个参数是nullQ因是静态方法,不需要借助实例q行?br />


5. 新徏实例
 1 
 2 public Object newInstance(String className, Object[] args) throws Exception {
 3     Class newoneClass = Class.forName(className);
 4 
 5     Class[] argsClass = new Class[args.length];
 6 
 7     for (int i = 0, j = args.length; i < j; i++) {
 8         argsClass[i] = args[i].getClass();
 9     }
10 
11     Constructor cons = newoneClass.getConstructor(argsClass);
12 
13     return cons.newInstance(args);
14 
15 }


q里说的Ҏ(gu)是执行带参数的构造函数来新徏实例的方法。如果不需要参敎ͼ可以直接使用newoneClass.newInstance()来实现?br />
Class newoneClass = Class.forName(className)Q第一步,得到要构造的实例的Class?br />
W?~第9行:得到参数的Class数组?br />
Constructor cons = newoneClass.getConstructor(argsClass)Q得到构造子?br />
cons.newInstance(args)Q新建实例?br />

6. 判断是否为某个类的实?br />
1 public boolean isInstance(Object obj, Class cls) {
2     return cls.isInstance(obj);
3 }



7. 得到数组中的某个元素
1 public Object getByArray(Object array, int index) {
2     return Array.get(array,index);
3 }



附完整源码:

import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;


/**
 * Java Reflection Cookbook
 *
 * 
@author Michael Lee
 * 
@since 2006-8-23
 * 
@version 0.1a
 
*/

public class Reflection {
    
/**
     * 得到某个对象的公共属?br />     *
     * 
@param owner, fieldName
     * 
@return 该属性对?br />     * @throws Exception
     *
     
*/
    
public Object getProperty(Object owner, String fieldName) throws Exception {
        Class ownerClass 
= owner.getClass();

        Field field 
= ownerClass.getField(fieldName);

        Object property 
= field.get(owner);

        
return property;
    }

    
/**
     * 得到某类的静态公共属?br />     *
     * 
@param className   cd
     * 
@param fieldName   属性名
     * 
@return 该属性对?br />     * @throws Exception
     
*/
    
public Object getStaticProperty(String className, String fieldName)
            
throws Exception {
        Class ownerClass 
= Class.forName(className);

        Field field 
= ownerClass.getField(fieldName);

        Object property 
= field.get(ownerClass);

        
return property;
    }


    
/**
     * 执行某对象方?br />     *
     * 
@param owner
     *            对象
     * 
@param methodName
     *            Ҏ(gu)?br />     * 
@param args
     *            参数
     * 
@return Ҏ(gu)q回?br />     * @throws Exception
     
*/
    
public Object invokeMethod(Object owner, String methodName, Object[] args)
            
throws Exception {

        Class ownerClass 
= owner.getClass();

        Class[] argsClass 
= new Class[args.length];

        
for (int i = 0, j = args.length; i < j; i++) {
            argsClass[i] 
= args[i].getClass();
        }

        Method method 
= ownerClass.getMethod(methodName, argsClass);

        
return method.invoke(owner, args);
    }


      
/**
     * 执行某类的静态方?br />     *
     * 
@param className
     *            cd
     * 
@param methodName
     *            Ҏ(gu)?br />     * 
@param args
     *            参数数组
     * 
@return 执行Ҏ(gu)q回的结?br />     * @throws Exception
     
*/
    
public Object invokeStaticMethod(String className, String methodName,
            Object[] args) 
throws Exception {
        Class ownerClass 
= Class.forName(className);

        Class[] argsClass 
= new Class[args.length];

        
for (int i = 0, j = args.length; i < j; i++) {
            argsClass[i] 
= args[i].getClass();
        }

        Method method 
= ownerClass.getMethod(methodName, argsClass);

        
return method.invoke(null, args);
    }



    
/**
     * 新徏实例
     *
     * 
@param className
     *            cd
     * 
@param args
     *            构造函数的参数
     * 
@return 新徏的实?br />     * @throws Exception
     
*/
    
public Object newInstance(String className, Object[] args) throws Exception {
        Class newoneClass 
= Class.forName(className);

        Class[] argsClass 
= new Class[args.length];

        
for (int i = 0, j = args.length; i < j; i++) {
            argsClass[i] 
= args[i].getClass();
        }

        Constructor cons 
= newoneClass.getConstructor(argsClass);

        
return cons.newInstance(args);

    }


    
    
/**
     * 是不是某个类的实?br />     * 
@param obj 实例
     * 
@param cls c?br />     * @return 如果 obj 是此cȝ实例Q则q回 true
     
*/
    
public boolean isInstance(Object obj, Class cls) {
        
return cls.isInstance(obj);
    }
    
    
/**
     * 得到数组中的某个元素
     * 
@param array 数组
     * 
@param index 索引
     * 
@return q回指定数组对象中烦引组件的?br />     */
    
public Object getByArray(Object array, int index) {
        
return Array.get(array,index);
    }
}


何智 2011-07-12 10:27 发表评论
]]>
java操作excel(HSSF样式一)http://www.aygfsteel.com/hezhi/articles/354143.html何智何智Tue, 12 Jul 2011 02:25:00 GMThttp://www.aygfsteel.com/hezhi/articles/354143.htmlhttp://www.aygfsteel.com/hezhi/comments/354143.htmlhttp://www.aygfsteel.com/hezhi/articles/354143.html#Feedback0http://www.aygfsteel.com/hezhi/comments/commentRss/354143.htmlhttp://www.aygfsteel.com/hezhi/services/trackbacks/354143.htmlimport java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

HSSFCellStylecM表一U单元格样式。可以通过q些cL讄单元格的Ҏ(gu)样式、背景颜艌Ӏ字体、水q_垂直方式的对齐?br />?
          HSSFWorkbook workbook = new HSSFWorkbook();    //建立一个工作薄
          HSSFCellStyle titleStyle=workbook.createCellStyle();     //在工作薄的基上徏立一个样?br />          titleStyle.setBorderBottom(HSSFCellStyle.BORDER_DOUBLE);    //讄Ҏ(gu)样式
          titleStyle.setBorderLeft((short)1);     //左边?br />          titleStyle.setBorderRight((short)1);    //双?br />          titleStyle.setBorderTop(HSSFCellStyle.BORDER_DOUBLE);    //边?br />          titleStyle.setFillForegroundColor(HSSFColor.LIGHT_ORANGE.index);    //填充的背景颜?br />          titleStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);    //填充图案

假设什么定义了一个样式,惛_填充W一个单元格的时候填充红Q第二格单元格填充蓝艌Ӏ?br />如果:
          HSSFCellStyle cellStyle = workbook.createCellStyle();    //创徏一个样?/font>

          cellStyle.setFillForegroundColor(HSSFColor.RED.index);    //讄颜色为红?br />          cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

          HSSFCell cell1 = row.createCell((short)1);     //l单元格cell1填充U色
          cell1.setCellStyle(cellStyle);

?       cellStyle.setFillForegroundColor(HSSFColor.BLUE.index);    //讄颜色?br />        
          HSSFCell cell2 = row.createCell((short)2);    //l单元格cell2填充蓝色
          cell2.setCellStyle(cellStyle);

q个时候会出现的现象是单元格cell1和cell2都变成了蓝色。遇到这U情况,要预先定义两U不同的单元格样式?/font>


当一个EXCEL文g同时需要很多大同小异的单元格样式时Q这样一一定义很麻烦。POI HSSF提供了一个HSSFCellUtilc(在org.apache.poi.           hssf.usermodel.contrib包)Q里面有几个Ҏ(gu)可以l过HSSFCellStyle直接讑֮单元格的样式Q但q几个方法会抛出NestableException?nbsp;          常,要处理这个异常,需要引用Apache的几个Common包:
commons-beanutils.jar
commons-beanutils-bean-collections.jar
commons-beanutils-core.jar
commons-lang.jar
commons-logging-api.jar

以下是其他各U情늚处理Q?br />1、中文处理:
要在通过POI生成的EXCEL中正常显CZ文,需要ؓ单元D|编码:
          cell.setEncoding(HSSFCell.ENCODING_UTF_16);
          cell.setCellValue("部门");

2、合q单元格Q?br />HSSFSheet.addMergedRegion(new Region())Ҏ(gu)可以合ƈ单元|Region()中的一个构造函数含有四个参敎ͼ分别代表起始行、v始列、结?nbsp;       行、结束列Q?br />          sheet.addMergedRegion(new Region(initRow, (short)(initCol-2), initRow + lists.size() - 1, (short)(initCol-2)));

3、公式的处理Q?br />HSSFCell.setCellFormula()Ҏ(gu)用来在EXCEL单元g写入公式?br />          cell = row.createCell((short)(dataFlag));
          cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
              cell.setCellFormula("SUM(" + getColLetter(initCol) + (listFlag+1) +":" + getColLetter(dataFlag-1) + (listFlag+1) +                   ")");
          cell.setCellStyle(nameStyle);

4、链接的处理Q?br />在POI中往单元g写链接,是用HYPERLINK函数搞定的?br />HYPERLINK函数包含两个参数Q第一个参数是指向的URL地址Q第二个参数是显C字丌Ӏ?br />     cell = row.createCell((short)(dataFlag));
     cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
     cell.setCellFormula("HYPERLINK(\"
http://www.xxxxx.com/xxx.jsp?id=1\",\"homepage\")");
     cell.setCellStyle(linkStyle);
Z佉K接效果更好,我们可以l链接所在单元格定义一U样式,佉K接显CZؓ有下划线的蓝色字Ԍ
    HSSFCellStyle linkStyle = workbook.createCellStyle();
    linkStyle.setBorderBottom((short)1);
    linkStyle.setBorderLeft((short)1);
    linkStyle.setBorderRight((short)1);
    linkStyle.setBorderTop((short)1);
    linkStyle.setFillForegroundColor(HSSFColor.SKY_BLUE.index);
    linkStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    HSSFFont font = workbook.createFont();
    font.setFontName(HSSFFont.FONT_ARIAL);
    font.setUnderline((byte)1);
    font.setColor(HSSFColor.BLUE.index);
    linkStyle.setFont(font);



何智 2011-07-12 10:25 发表评论
]]>
一个POI Excel的小例子【{?/title><link>http://www.aygfsteel.com/hezhi/articles/354141.html</link><dc:creator>何智</dc:creator><author>何智</author><pubDate>Tue, 12 Jul 2011 02:20:00 GMT</pubDate><guid>http://www.aygfsteel.com/hezhi/articles/354141.html</guid><wfw:comment>http://www.aygfsteel.com/hezhi/comments/354141.html</wfw:comment><comments>http://www.aygfsteel.com/hezhi/articles/354141.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/hezhi/comments/commentRss/354141.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/hezhi/services/trackbacks/354141.html</trackback:ping><description><![CDATA[     摘要: 原文Qhttp://www.iteye.com/problems/13427 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->  1package *.*;     ...  <a href='http://www.aygfsteel.com/hezhi/articles/354141.html'>阅读全文</a><img src ="http://www.aygfsteel.com/hezhi/aggbug/354141.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/hezhi/" target="_blank">何智</a> 2011-07-12 10:20 <a href="http://www.aygfsteel.com/hezhi/articles/354141.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java的POI操作Excel文ghttp://www.aygfsteel.com/hezhi/articles/POI.html何智何智Mon, 04 Jul 2011 08:10:00 GMThttp://www.aygfsteel.com/hezhi/articles/POI.htmlhttp://www.aygfsteel.com/hezhi/comments/353651.htmlhttp://www.aygfsteel.com/hezhi/articles/POI.html#Feedback0http://www.aygfsteel.com/hezhi/comments/commentRss/353651.htmlhttp://www.aygfsteel.com/hezhi/services/trackbacks/353651.html阅读全文

何智 2011-07-04 16:10 发表评论
]]>
վ֩ģ壺 ޽| ʲ| ƽ| | ɽ| ɽ| Դ| Դ| | ƺ| ʯ| ǭ| ̴| ˿| | ά| ̶| ٲ| ԭ| ͬ| | | ػʵ| | | | | ɽ| | | ɽ| | | Ϊ| ũ| | ¡| | Т| | ר|