﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-J2EE</title><link>http://www.blogjava.net/fonhal/</link><description>Java/J2EE Struts Spring</description><language>zh-cn</language><lastBuildDate>Mon, 13 Apr 2026 08:52:50 GMT</lastBuildDate><pubDate>Mon, 13 Apr 2026 08:52:50 GMT</pubDate><ttl>60</ttl><item><title>ROR学习笔记系列三 Rails数据库操作入门 ---Oracle 10g数据库操作</title><link>http://www.blogjava.net/fonhal/archive/2009/01/14/251232.html</link><dc:creator>fonhal</dc:creator><author>fonhal</author><pubDate>Wed, 14 Jan 2009 03:23:00 GMT</pubDate><guid>http://www.blogjava.net/fonhal/archive/2009/01/14/251232.html</guid><wfw:comment>http://www.blogjava.net/fonhal/comments/251232.html</wfw:comment><comments>http://www.blogjava.net/fonhal/archive/2009/01/14/251232.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/fonhal/comments/commentRss/251232.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/fonhal/services/trackbacks/251232.html</trackback:ping><description><![CDATA[<blockquote> <div>&nbsp;&nbsp;&nbsp;&nbsp; 最近由于忙于考研,所以是在是耽误了不少的时间和精力,所以造成了我脱离网络一段时间,搞得我是考研考的不好,结果这个学习的过程也给耽误了,哎....考研,原来真的不是儿戏...还是要复习的,原来以为考研应该随便看看的话在理想的估计差不多的吧...差不多每一科都及格了就好了...但是现在发现原来不是这个样子的....知识点太多了..一下子搞不定的..怪不得大家都是要复习那么长时间....看来下次如果要考研的话我一定要去好好复习一下...免得有对不起自己了,废话不多说了.现在开始这个学习笔记系列的第三个部分,使用Oracle 10g进行ROR的数据库操作．上次我们说了使用Mysql的环境.但是由于我现在项目开发中一直使用的是Oracle数据库,而且在两个都是大同小异.所以现在开始我们就是用Oracle数据库进行操作.必要的时候也会提及一下MySQL的</div> <p>&nbsp;&nbsp;&nbsp;&nbsp; 首先,我们来安装一下Oracle的环境.主要是Ruby驱动和ActiveRecord adapter的支持.</p> <p>&nbsp;&nbsp;&nbsp; 从rails 2.0开始, ActiveRecord对于商业数据库的adapter的支持已经取消了,只有Mysql和SQLlite的支持了吧.所以对于其他的部分的话要自己独立的安装,</p> <p>安装activerecord-oracle-adapter使用下面的命令:</p></blockquote> <blockquote> <div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.52%; padding-right: 4px; font-family: consolas, 'Courier New', courier, monospace; height: 31px; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px"><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">gem install activerecord-oracle-adapter --source <a href="http://gems.rubyonrails.org">http://gems.rubyonrails.org</a> </pre></div>
<p>如果要安装sqlserver的话可以将oracle换成sqlserver进行安装</p></blockquote>
<blockquote>
<p>或者从下面下载加强版本的Adapter:</p>
<p><a title="http://rubyforge.org/frs/?group_id=6212&amp;release_id=22063" href="http://rubyforge.org/frs/?group_id=6212&amp;release_id=22063">http://rubyforge.org/frs/?group_id=6212&amp;release_id=22063</a> 中下载最新版本1.1.9</p>
<p><a title="http://rubyforge.org/frs/download.php/49541/activerecord-oracle_enhanced-adapter-1.1.9.gem" href="http://rubyforge.org/frs/download.php/49541/activerecord-oracle_enhanced-adapter-1.1.9.gem">http://rubyforge.org/frs/download.php/49541/activerecord-oracle_enhanced-adapter-1.1.9.gem</a></p>
<p>安装ruby-oci8驱动</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.98%; padding-right: 4px; font-family: consolas, 'Courier New', courier, monospace; height: 33px; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<p>gem install ruby-oci8 </p></div>
<p>下载地址是:<a href="http://www.rubyforge.org/projects/ruby-oci8">http://www.rubyforge.org/projects/ruby-oci8</a></p>
<p>好了,安装完成了之后我们可以使用一个ruby的测试,来查看我们是否安装成功!</p>
<div>
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">require <span style="color: #006080">'rubygems'</span></pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">require <span style="color: #006080">'active_record'</span></pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">class</span> Account &lt; ActiveRecord::Base</pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">  set_table_name <span style="color: #006080">"account"</span> #设置表名</pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">end</pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">ActiveRecord::Base.establish_connection(</pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">  :adapter  =&gt; <span style="color: #006080">"oracle"</span>,#数据库适配器</pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">  :database =&gt; <span style="color: #006080">"xe"</span>,#数据库SID</pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">  :username =&gt; <span style="color: #006080">"fonhal"</span>,#数据库用户名</pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">  :password =&gt; <span style="color: #006080">"123123"</span> #数据库用户密码</pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">)</pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">account = Account.find(:first,:conditions =&gt;<span style="color: #006080">"USERID = 'j2ee'"</span>) #查询数据库</pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">puts <span style="color: #006080">"#{account.userid}  #{ account.email}        #{ account.firstname}        "</span> </pre></div></div>
<div>对于不同的用户要进行更换数据库的相关配置和表名.</div>
<div>如果成功的话测试结果如下:</div>
<div><a href="http://www.blogjava.net/images/blogjava_net/fonhal/WindowsLiveWriter/RORRailsOracle10g_CA7C/image_2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/fonhal/WindowsLiveWriter/RORRailsOracle10g_CA7C/image_thumb.png" width="709" height="66"></a> </div>
<div>&nbsp;</div>
<div>好了,Oracle数据库驱动配置好了.现在我们开始一个简单的Rails和Oracle 数据库的链接的Demo吧!</div>
<div>1. 打开Aptana,然后创建一个Rails Project.数据源选择Oralce, 然后Rails版本选择2.2.2版本</div>
<div><a target="_blank" href="http://www.blogjava.net/images/blogjava_net/fonhal/WindowsLiveWriter/RORRailsOracle10g_CA7C/image_4.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/fonhal/WindowsLiveWriter/RORRailsOracle10g_CA7C/image_thumb_1.png" width="332" height="317"></a> </div>
<div>2. 创建好项目之后我们使用可以scaffold产生一个Model和数据库迁移配置产生一个版本文件.如果我们不想使用这种方式那也可以的直接使用下面的命令进行数据库迁移:</div>
<div>
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">rake db:migrate </pre></div></div>
<div>(如果这里不可以的话可能还是需要创建一个model或者使用scaffold进行创建.然后在使用上面的命令,因为我是之前使用过scaffold进行创建了一个Demo,所以在数据库中有一个schema_migrations的文件记录着当前用户的迁移版本信息.这样的话方便如果改变了表格等进行数据库的回滚操作.迁移到上一数据库表的版本.</div>
<div>这个时候会在db下产生一个schema.rb文件,里面记录着当前用户下的所有用户表的信息,例如:</div>
<div>
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">ActiveRecord::Schema.define(:version =&gt; 20090114020840) <span style="color: #0000ff">do</span></pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&nbsp;</pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">  create_table <span style="color: #006080">"account"</span>, :primary_key =&gt; <span style="color: #006080">"userid"</span>, :force =&gt; <span style="color: #0000ff">true</span> <span style="color: #0000ff">do</span> |t|</pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    t.<span style="color: #0000ff">string</span> <span style="color: #006080">"email"</span>,     :limit =&gt; 80, :<span style="color: #0000ff">null</span> =&gt; <span style="color: #0000ff">false</span></pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    t.<span style="color: #0000ff">string</span> <span style="color: #006080">"firstname"</span>, :limit =&gt; 80, :<span style="color: #0000ff">null</span> =&gt; <span style="color: #0000ff">false</span></pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    t.<span style="color: #0000ff">string</span> <span style="color: #006080">"lastname"</span>,  :limit =&gt; 80, :<span style="color: #0000ff">null</span> =&gt; <span style="color: #0000ff">false</span></pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    t.<span style="color: #0000ff">string</span> <span style="color: #006080">"status"</span>,    :limit =&gt; 2</pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    t.<span style="color: #0000ff">string</span> <span style="color: #006080">"addr1"</span>,     :limit =&gt; 80, :<span style="color: #0000ff">null</span> =&gt; <span style="color: #0000ff">false</span></pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    t.<span style="color: #0000ff">string</span> <span style="color: #006080">"addr2"</span>,     :limit =&gt; 40</pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    t.<span style="color: #0000ff">string</span> <span style="color: #006080">"city"</span>,      :limit =&gt; 80, :<span style="color: #0000ff">null</span> =&gt; <span style="color: #0000ff">false</span></pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    t.<span style="color: #0000ff">string</span> <span style="color: #006080">"state"</span>,     :limit =&gt; 80, :<span style="color: #0000ff">null</span> =&gt; <span style="color: #0000ff">false</span></pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    t.<span style="color: #0000ff">string</span> <span style="color: #006080">"zip"</span>,       :limit =&gt; 20, :<span style="color: #0000ff">null</span> =&gt; <span style="color: #0000ff">false</span></pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    t.<span style="color: #0000ff">string</span> <span style="color: #006080">"country"</span>,   :limit =&gt; 20, :<span style="color: #0000ff">null</span> =&gt; <span style="color: #0000ff">false</span></pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    t.<span style="color: #0000ff">string</span> <span style="color: #006080">"phone"</span>,     :limit =&gt; 80, :<span style="color: #0000ff">null</span> =&gt; <span style="color: #0000ff">false</span></pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">  end</pre><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">end</pre></div></div>
<div>在这个表里面就是当前用户的表信息,创建新的表的话应该也是可以在里面进行添加.和我们使用model创建的的迁移文件应该是一样的.</div>
<div>3.如果不想使用scaffold的话那现在如果上面的命令执行结束的话那就可以自己去建立页面然后进行操作,但是这样的话可能要浪费时间一点.下面我先给出一个使用scaffold的方式创建的Demo:</div>
<div>
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">script/generate scaffold post title:<span style="color: #0000ff">string</span> author:<span style="color: #0000ff">string</span> description:text</pre></div>产生一个post模型,并且在db/migrate/下产生一个迁移文件.文件名为当前的schema的版本,我们也是测试创建博客的例子.创建结束之后,当然还是进行数据库迁移操作,使用rake db:migrate进行数据库迁移.</div>
<div>4. 上面的操作好了之后的话启动服务器,选择servers Tab.然后找到当前项目名称对应的服务,然后选择启动,默认创建服务器的时候会使用mongle作为服务器,如果出现了服务器不能够启动的话可能是因为默认使用的3000端口已经有工程占用了.右键点击项目服务器选择 edit server更改端口号和他的其他配置都可以.启动服务器之后使用</div>
<div><a title="http://127.0.0.1:3002/posts" href="http://127.0.0.1:3002/posts">http://127.0.0.1:3002/posts</a> 来打开网页,我们可以看到POST的示例已经创建好了如图:</div>
<div><a target="_blank" href="http://www.blogjava.net/images/blogjava_net/fonhal/WindowsLiveWriter/RORRailsOracle10g_CA7C/image_6.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/fonhal/WindowsLiveWriter/RORRailsOracle10g_CA7C/image_thumb_2.png" width="288" height="150"></a> </div>
<div>选择New Post可以创建新的post:</div>
<div><a target="_blank" href="http://www.blogjava.net/images/blogjava_net/fonhal/WindowsLiveWriter/RORRailsOracle10g_CA7C/image_8.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/fonhal/WindowsLiveWriter/RORRailsOracle10g_CA7C/image_thumb_3.png" width="279" height="312"></a> </div>
<div>这样的话一个博客的Demo就创建好了!对于其中使用Scaffold创建的代码如果不想使用的话可以自己根据它的他妈进行创建自己的代码,不适用Scaffold的方式.这是创建了一个post后的预览.(<font color="#ff0000">貌似"过程"乱码了.....不是过稣..大家看看会不会出现乱码!)</font></div>
<div><a href="http://www.blogjava.net/images/blogjava_net/fonhal/WindowsLiveWriter/RORRailsOracle10g_CA7C/image_10.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.blogjava.net/images/blogjava_net/fonhal/WindowsLiveWriter/RORRailsOracle10g_CA7C/image_thumb_4.png" width="695" height="188"></a> </div>
<div>不过我个人而言觉得使用Scaffold这种方式的话是一个很好的选择,当然对于以后熟悉了ROR的相关的一些知识之后,使用这种方式可能会很方便.但是如果对于初学者的话肯定都是愿意写自己的代码.好了.本次学习到此为止,现在大家已经基本上能够创建一个ROR的示例,并且和数据库进行对联,下一次我对于使用Scaffold创建的代码进行一个说明,并且创建不适用Scaffold的方式的给大家一个展示.</div>
<div>&nbsp;</div></blockquote><img src ="http://www.blogjava.net/fonhal/aggbug/251232.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/fonhal/" target="_blank">fonhal</a> 2009-01-14 11:23 <a href="http://www.blogjava.net/fonhal/archive/2009/01/14/251232.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ROR 学习笔记系列二 基于ROR的简单Hello World程序入门</title><link>http://www.blogjava.net/fonhal/archive/2009/01/02/249552.html</link><dc:creator>fonhal</dc:creator><author>fonhal</author><pubDate>Fri, 02 Jan 2009 08:15:00 GMT</pubDate><guid>http://www.blogjava.net/fonhal/archive/2009/01/02/249552.html</guid><wfw:comment>http://www.blogjava.net/fonhal/comments/249552.html</wfw:comment><comments>http://www.blogjava.net/fonhal/archive/2009/01/02/249552.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/fonhal/comments/commentRss/249552.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/fonhal/services/trackbacks/249552.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;&nbsp;&nbsp;&nbsp; 本篇是本系列的第二个教程,在本章里面我将就开发一个简单的ROR Hello World程序帮助大家入门,任何程序入门都会使用Hello World!这个程序设计里面的经典,使用率最高,几乎每个程序设计人员都写过.当然我个人写程序最入门的我也一般是先写一个Hello World程序来进行入门...好了,下面我们开始吧! &nbsp;&nbsp; 首先...&nbsp;&nbsp;<a href='http://www.blogjava.net/fonhal/archive/2009/01/02/249552.html'>阅读全文</a><img src ="http://www.blogjava.net/fonhal/aggbug/249552.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/fonhal/" target="_blank">fonhal</a> 2009-01-02 16:15 <a href="http://www.blogjava.net/fonhal/archive/2009/01/02/249552.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ROR 学习笔记系列一 Windows XP下环境安装配置</title><link>http://www.blogjava.net/fonhal/archive/2009/01/02/249530.html</link><dc:creator>fonhal</dc:creator><author>fonhal</author><pubDate>Fri, 02 Jan 2009 04:37:00 GMT</pubDate><guid>http://www.blogjava.net/fonhal/archive/2009/01/02/249530.html</guid><wfw:comment>http://www.blogjava.net/fonhal/comments/249530.html</wfw:comment><comments>http://www.blogjava.net/fonhal/archive/2009/01/02/249530.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/fonhal/comments/commentRss/249530.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/fonhal/services/trackbacks/249530.html</trackback:ping><description><![CDATA[<blockquote> <p>&nbsp;&nbsp;&nbsp; 最近刚刚结束一个项目,闲着无聊,所以准备学习一下ROR给自己充一下电,在JavaEye上面看到ROR很久了,但是一直由于比较忙着一个Java的项目,所以也没有多关注,最近也是无意之间看见Robbin大哥关于2009年热门技术中关于ROR的预测,还有2009年的10项热门技术中都对Rails非常推崇,就连JavaEye本身也是基于ROR的.所以我想我也有必要去学习一下这门技术.不然真的会脱离IT这个行业(汗...20出头就被淘汰了..),好了废话不多说.首先介绍一下ROR(当然学习前提是对于Ruby和MVC都有所掌握...):</p> <li><em>Ruby</em> 是一门免费的、简单的、直观的、可扩展的、可移植的、解释的脚本语言，用于快速而简单的面向对象编程。类似于 Perl，它支持处理文本文件和执行系统管理任务的很多特性。  <li><em>Rails</em> 是用 Ruby 编写的一款完整的、开放源代码的 Web 框架，目的是使用更简单而且更少的代码编写实际使用的应用程序。</li></blockquote> <blockquote> <p><em>好了,首先我们来搭建一下开发环境,我的开发环境是Windows XP Professional SP3 + <strong>ruby 1.8.6 + Rails 2.2.2 + </strong></em><strong>Mongrel</strong><em><strong> + MySQL 5.1</strong>:</em></p> <p>1. 首先我们安装Ruby,最好下载一个One-Click Installer,下载地址是<a title="http://rubyforge.org/frs/download.php/29263/ruby186-26.exe" href="http://rubyforge.org/frs/download.php/29263/ruby186-26.exe">http://rubyforge.org/frs/download.php/29263/ruby186-26.exe</a></p> <p>然后直接按照安装提示进行安装就好了.我的安装路径是C:\ruby\下,环境变量也会自动创建好.测试一下:</p> <p><a href="http://www.blogjava.net/images/blogjava_net/fonhal/WindowsLiveWriter/ROR1WindowsXP_9429/image_2.png" target="_blank"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="54" alt="image" src="http://www.blogjava.net/images/blogjava_net/fonhal/WindowsLiveWriter/ROR1WindowsXP_9429/image_thumb.png" width="470" border="0"></a> </p> <p>创建一个HelloWorld的rb测试文件.</p> <p>test.rb</p> <p><a href="http://www.blogjava.net/images/blogjava_net/fonhal/WindowsLiveWriter/ROR1WindowsXP_9429/image_4.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="58" alt="image" src="http://www.blogjava.net/images/blogjava_net/fonhal/WindowsLiveWriter/ROR1WindowsXP_9429/image_thumb_1.png" width="284" border="0"></a> </p> <p>helloworld = "Hello World!"<br>puts helloworld;  <p>或者在FXRI中直接定义一个函数hello来打印输出:  <p>irb(main):007:0&gt; def hello()<br>irb(main):008:1&gt;&nbsp;&nbsp; puts "Hello World"<br>irb(main):009:1&gt;&nbsp;&nbsp; end<br>=&gt; nil<br>irb(main):010:0&gt; hello<br>Hello World<br>=&gt; nil  <p>或者在控制台中输入:  <p>C:\&gt;ruby -e 'puts "Helllo World"'<br>Helllo World  <p>都可以测试安装是否完成,如果能够正常运行程序,当然我们可以说他的环境是安装好的.  <p>在这种安装方式中已经是安装好了gem,可以使用gem update来对gem进行更新.更新所有的Gem安装文件,gem最新版本是1.3.1版本(在我写这篇文章的时候我还update了一下).  <p>2. 安装Rails,安装 Rails 我使用gem进行安装,如果网络不好的话就只能够下载安装了,gem安装方式如下:  <p>在命令行下输入:  <p><strong>gem install rails –include-dependencies</strong></p></blockquote> <blockquote> <p><a href="http://www.blogjava.net/images/blogjava_net/fonhal/WindowsLiveWriter/ROR1WindowsXP_9429/image_6.png" target="_blank"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="328" alt="image" src="http://www.blogjava.net/images/blogjava_net/fonhal/WindowsLiveWriter/ROR1WindowsXP_9429/image_thumb_2.png" width="481" border="0"></a> </p> <p>使用Rails -v进行查看.</p> <p><a href="http://www.blogjava.net/images/blogjava_net/fonhal/WindowsLiveWriter/ROR1WindowsXP_9429/image_8.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="45" alt="image" src="http://www.blogjava.net/images/blogjava_net/fonhal/WindowsLiveWriter/ROR1WindowsXP_9429/image_thumb_3.png" width="256" border="0"></a> </p> <p>可以看到Rails已经成功安装了,</p> <p>如果网络不好的话可以自己下载Gem来进行本地安装,安装顺序和上面的安装顺序一样就好了.</p> <p><strike>rake-0.8.3<br>activesupport-2.2.2<br>activerecord-2.2.2<br>actionpack-2.2.2<br>actionmailer-2.2.2<br>activeresource-2.2.2<br>rails-2.2.2</strike>  <p>自己到&nbsp; <a href="http://rubyforge.org/projects/">http://rubyforge.org/projects/</a> 进行搜索查找,主意版本之间依赖.</p> <p>3. 安装Mongrel 作为我们的ROR Web Server.服务器我们使用Mongrel,不使用默认的Webrick,因为在速度上面便利性上Webrick都不如Mongrel,所以我们选择Mongrel</p> <p>安装方法还是使用Gem的方式安装:</p> <p><strong>gem install mongrel –include-dependencies</strong>  <p>安装Mongrel_service:  <p><strong>gem install mongrel_service –include-dependencies</strong>  <p>目前最新版本是:  <p>mongrel (1.1.5)<br>mongrel_service (0.3.4)  <p>在命令行下输入:  <p><strong>mongrel_rails service::install -N WebServer -c E:\WebSites -e development</strong>  <p>来创建服务,-N 表示Windows NT的服务名. WebServer是创建的Windows 服务名, –c 后面跟本地路径 E:\WebSites&nbsp; 然后-e表示环境,我们选择的development开发环境,也可以选择test测试环境或者production产品环境.  <p>这样的话你就可以在Windows的服务中找到WebServer这个服务了,和正常启动Windows服务的方式一样来启动Mongrel服务.  <p>删除服务使用:  <p><strong>mongrel_rails service::remove -N WebServer</strong>  <p>4.安装Mysql 数据库, 下载地址:<a href="http://dev.mysql.com/downloads/mysql">http://dev.mysql.com/downloads/mysql</a>  <p><a title="http://ftp.iij.ad.jp/pub/db/mysql/Downloads/MySQL-5.1/mysql-5.1.30-win32.zip" href="http://ftp.iij.ad.jp/pub/db/mysql/Downloads/MySQL-5.1/mysql-5.1.30-win32.zip">http://ftp.iij.ad.jp/pub/db/mysql/Downloads/MySQL-5.1/mysql-5.1.30-win32.zip</a>  <p>安装完成侯使用Config Wizard进行配置.配置完成之后把Lib/opt下的ibmySQL.dll拷贝到Ruby的bin目录下,  <p>在MySQL命令行中创建数据库:  <p>create database WebServer_development;  <p>创建完成之后退出.  <p>然后安装MySQL 的Ruby驱动,使用Gem安装方式:  <p><strong>gem install mysql</strong>  <p>通过Gem可以安装的最新版本2.7.3版本,实际上最新已经是2.8版本的.但是不能够通过Gem方式安装.安装2.7.3在结束的时候会出现一个问题就是创建rdoc的时候由一个问 <p>题,这个问题不影响MySQL驱动的使用,所以也不要太在意.安装完成之后退出.或者到网址<a href="http://rubyforge.org/projects/mysql-win">http://rubyforge.org/projects/mysql-win</a>下载mysql-2.7.3-mswin32.gem本地安装使用的Gem命令(在当前的mysql驱动所在路径下)是:gem install –l mysql-2.7.3-mswin32.gem 或者不用-l他会在本地查找.  <p>&nbsp; 到现在为止全部的环境都已经安装完毕!有什么不妥之处,敬请指正,本人也是带着学习的目的,和大家一起进步,同时也是对自己学习的过程进行一个记录,希望能够对别人有帮助,请勿拍砖!下一篇我将就开发一个简单的Hello World程序来进行演示.</p> <div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:68283723-d60c-4fdd-9505-6dd3497daca6" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">Flickr Tags: <a href="http://flickr.com/photos/tags/ROR+Rails+Ruby+%e7%8e%af%e5%a2%83+%e9%85%8d%e7%bd%ae" rel="tag">ROR Rails Ruby 环境 配置</a></div></blockquote><img src ="http://www.blogjava.net/fonhal/aggbug/249530.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/fonhal/" target="_blank">fonhal</a> 2009-01-02 12:37 <a href="http://www.blogjava.net/fonhal/archive/2009/01/02/249530.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PL\SQL 打开时出现&amp;quot;动态执行表不可访问，本会话的自动统计被禁止&amp;quot;错误解决</title><link>http://www.blogjava.net/fonhal/archive/2008/12/31/249369.html</link><dc:creator>fonhal</dc:creator><author>fonhal</author><pubDate>Wed, 31 Dec 2008 10:08:00 GMT</pubDate><guid>http://www.blogjava.net/fonhal/archive/2008/12/31/249369.html</guid><wfw:comment>http://www.blogjava.net/fonhal/comments/249369.html</wfw:comment><comments>http://www.blogjava.net/fonhal/archive/2008/12/31/249369.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/fonhal/comments/commentRss/249369.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/fonhal/services/trackbacks/249369.html</trackback:ping><description><![CDATA[<blockquote> <p>最近做J2ee开发的时候使用PL/SQL,但是每次第一次打开表的时候会提示"动态执行表不可访问，本会话的自动统计被禁止"的错误,一消息如下: V$SESSION,V$SESSTAT,V$STATNAME没有被授权,没有权限访问这几张表,所以没有本法进行统计.当然要给授权了.授权SQL如下:</p> <p>grant select on v_$statname to user;<br>grant select on v_$sesstat to user;<br>grant select on v_$session to user;<br>grant select on v_$mystat to user;  <p>user就是要被授权的用户名.记下以备后用.</p></blockquote><img src ="http://www.blogjava.net/fonhal/aggbug/249369.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/fonhal/" target="_blank">fonhal</a> 2008-12-31 18:08 <a href="http://www.blogjava.net/fonhal/archive/2008/12/31/249369.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>