Home Database Mysql Tutorial Oracle 在Spring+Hibernate中的使用

Oracle 在Spring+Hibernate中的使用

Jun 07, 2016 pm 02:50 PM
oracle use

本文会基于一个搭建好的工程更新配置文件完成。 1、准备 您需要一个搭建好的SpringHibernate工程。 可以直接参考(含下载):Eclipse搭建Maven工程集成Spring4Hibernate5SpringMVC 2、jdbc驱动 若已安装Oracle,在Oracle主目录中有,比如本人的为:C:\app\ia

   本文会基于一个搭建好的工程更新配置文件完成。

1、准备

    您需要一个搭建好的Spring+Hibernate工程。

    可以直接参考(含下载):Eclipse搭建Maven工程集成Spring4+Hibernate5+SpringMVC

2、jdbc驱动

    若已安装Oracle,在Oracle主目录中有,比如本人的为:C:\app\iamanxpp\product\12.1.0\dbhome_1\jdbc。

    把ojdbc7.jar添加到工程中即可。

    因为为Maven工程,添加jar包方式如下:

<ol class="linenums" style="padding:0px 0px 0px 10px; margin:0px; border-left-width:30px; border-left-style:solid; border-left-color:rgb(79,54,57); list-style-type:decimal-leading-zero; color:rgb(176,235,231)"><li class="L0" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">      </span><span class="tag" style="color:rgb(0,150,219)"><dependency></span></li><li class="L1" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">            </span><span class="tag" style="color:rgb(0,150,219)"><groupId></span><span class="pln" style="color:rgb(198,249,131)">com.oracle</span><span class="tag" style="color:rgb(0,150,219)"></groupId></span></li><li class="L2" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">            </span><span class="tag" style="color:rgb(0,150,219)"><artifactId></span><span class="pln" style="color:rgb(198,249,131)">ojdbc14</span><span class="tag" style="color:rgb(0,150,219)"></artifactId></span></li><li class="L3" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">            </span><span class="tag" style="color:rgb(0,150,219)"><version></span><span class="pln" style="color:rgb(198,249,131)">10.2.0.4.0</span><span class="tag" style="color:rgb(0,150,219)"></version></span></li><li class="L4" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">            </span><span class="tag" style="color:rgb(0,150,219)"><scope></span><span class="pln" style="color:rgb(198,249,131)">system</span><span class="tag" style="color:rgb(0,150,219)"></scope></span></li><li class="L5" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">            </span><span class="tag" style="color:rgb(0,150,219)"><systemPath></span><span class="pln" style="color:rgb(198,249,131)">C:\java\workspace\web\Oracle12JDBC\lib\ojdbc7.jar</span><span class="tag" style="color:rgb(0,150,219)"></systemPath></span></li><li class="L6" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">        </span><span class="tag" style="color:rgb(0,150,219)"></dependency></span></li></ol>
Copy after login

其中systemPath请填入您实际的jdbc地址。

如果web容器使用tomcat,请将ojdbc7.jar同时添加到tomcat中的lib目录,比如本人为:

<ol class="linenums" style="padding:0px 0px 0px 10px; margin:0px; border-left-width:30px; border-left-style:solid; border-left-color:rgb(79,54,57); list-style-type:decimal-leading-zero; color:rgb(176,235,231)"><li class="L0" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">C</span><span class="pun" style="color:rgb(204,153,153)">:</span><span class="pln" style="color:rgb(198,249,131)">\java\apache</span><span class="pun" style="color:rgb(204,153,153)">-</span><span class="pln" style="color:rgb(198,249,131)">tomcat</span><span class="pun" style="color:rgb(204,153,153)">-</span><span class="lit" style="color:rgb(128,255,128)">7.0</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="lit" style="color:rgb(128,255,128)">61</span><span class="pln" style="color:rgb(198,249,131)">\lib</span></li></ol>
Copy after login

下面开始更新项目的配置。

3、配置文件

db.properties

请修改相关参数为您实际的值:

<ol class="linenums" style="padding:0px 0px 0px 10px; margin:0px; border-left-width:30px; border-left-style:solid; border-left-color:rgb(79,54,57); list-style-type:decimal-leading-zero; color:rgb(176,235,231)"><li class="L0" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="com" style="color:rgb(145,251,250)">#Oracle</span></li><li class="L1" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">jdbc</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="pln" style="color:rgb(198,249,131)">driverClassName</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="pln" style="color:rgb(198,249,131)">oracle</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="pln" style="color:rgb(198,249,131)">jdbc</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="pln" style="color:rgb(198,249,131)">driver</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="typ" style="color:rgb(246,105,154)">OracleDriver</span></li><li class="L2" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">jdbc</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="pln" style="color:rgb(198,249,131)">url</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="pln" style="color:rgb(198,249,131)">jdbc</span><span class="pun" style="color:rgb(204,153,153)">:</span><span class="pln" style="color:rgb(198,249,131)">oracle</span><span class="pun" style="color:rgb(204,153,153)">:</span><span class="pln" style="color:rgb(198,249,131)">thin</span><span class="pun" style="color:rgb(204,153,153)">:@</span><span class="com" style="color:rgb(145,251,250)">//127.0.0.1:1521/orcl</span></li><li class="L3" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">jdbc</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="pln" style="color:rgb(198,249,131)">username</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="pln" style="color:rgb(198,249,131)">yourusername</span></li><li class="L4" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">jdbc</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="pln" style="color:rgb(198,249,131)">password</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="pln" style="color:rgb(198,249,131)">yourpassword</span></li></ol>
Copy after login

applicationContext.xml

数据源的配置请保证如下:

<ol class="linenums" style="padding:0px 0px 0px 10px; margin:0px; border-left-width:30px; border-left-style:solid; border-left-color:rgb(79,54,57); list-style-type:decimal-leading-zero; color:rgb(176,235,231)"><li class="L0" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">  </span><span class="tag" style="color:rgb(0,150,219)"><context:property-placeholder</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">location</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"classpath:/db.properties"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)">/></span></li><li class="L1" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">    </span><span class="tag" style="color:rgb(0,150,219)"><bean</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">id</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"dataSource"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">class</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"org.apache.commons.dbcp.BasicDataSource"</span></li><li class="L2" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">        </span><span class="atn" style="color:rgb(255,204,51)">destroy-method</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"close"</span><span class="tag" style="color:rgb(0,150,219)">></span></li><li class="L3" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">        </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"driverClassName"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">value</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"${jdbc.driverClassName}"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)">/></span></li><li class="L4" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">        </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"url"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">value</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"${jdbc.url}"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)">/></span></li><li class="L5" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">        </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"username"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">value</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"${jdbc.username}"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)">/></span></li><li class="L6" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">        </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"password"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">value</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"${jdbc.password}"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)">/></span></li><li class="L7" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">        </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"maxActive"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">value</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"100"</span><span class="tag" style="color:rgb(0,150,219)">></property></span></li><li class="L8" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">        </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"minIdle"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">value</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"20"</span><span class="tag" style="color:rgb(0,150,219)">></property></span></li><li class="L9" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">        </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"maxWait"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">value</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"3000"</span><span class="tag" style="color:rgb(0,150,219)">></property></span></li><li class="L0" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">        </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"initialSize"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">value</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"30"</span><span class="tag" style="color:rgb(0,150,219)">></property></span></li><li class="L1" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">    </span><span class="tag" style="color:rgb(0,150,219)"></bean></span></li></ol>
Copy after login

各大数据库sql是有差别的,需要配置方言:

<ol class="linenums" style="padding:0px 0px 0px 10px; margin:0px; border-left-width:30px; border-left-style:solid; border-left-color:rgb(79,54,57); list-style-type:decimal-leading-zero; color:rgb(176,235,231)"><li class="L0" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">  </span><span class="tag" style="color:rgb(0,150,219)"><bean</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">id</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"sessionFactory"</span></li><li class="L1" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">        </span><span class="atn" style="color:rgb(255,204,51)">class</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"org.springframework.orm.hibernate5.LocalSessionFactoryBean"</span><span class="tag" style="color:rgb(0,150,219)">></span></li><li class="L2" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">        </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"dataSource"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">ref</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"dataSource"</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="tag" style="color:rgb(0,150,219)">/></span></li><li class="L3" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">        </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"packagesToScan"</span><span class="tag" style="color:rgb(0,150,219)">></span></li><li class="L4" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">            </span><span class="tag" style="color:rgb(0,150,219)"><list></span></li><li class="L5" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">                </span><span class="tag" style="color:rgb(0,150,219)"><value></span><span class="pln" style="color:rgb(198,249,131)">com.anxpp.demo.core.entity</span><span class="tag" style="color:rgb(0,150,219)"></value></span></li><li class="L6" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">            </span><span class="tag" style="color:rgb(0,150,219)"></list></span></li><li class="L7" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">        </span><span class="tag" style="color:rgb(0,150,219)"></property></span></li><li class="L8" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">        </span><span class="tag" style="color:rgb(0,150,219)"><property</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">name</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"hibernateProperties"</span><span class="tag" style="color:rgb(0,150,219)">></span></li><li class="L9" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">            </span><span class="tag" style="color:rgb(0,150,219)"><props></span></li><li class="L0" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">                </span><span class="tag" style="color:rgb(0,150,219)"><prop</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">key</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"hibernate.dialect"</span><span class="tag" style="color:rgb(0,150,219)">></span><span class="pln" style="color:rgb(198,249,131)">org.hibernate.dialect.OracleDialect</span><span class="tag" style="color:rgb(0,150,219)"></prop></span></li><li class="L1" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">                </span><span class="tag" style="color:rgb(0,150,219)"><prop</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">key</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"hibernate.show_sql"</span><span class="tag" style="color:rgb(0,150,219)">></span><span class="pln" style="color:rgb(198,249,131)">false</span><span class="tag" style="color:rgb(0,150,219)"></prop></span></li><li class="L2" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">                </span><span class="tag" style="color:rgb(0,150,219)"><prop</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">key</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"hibernate.format_sql"</span><span class="tag" style="color:rgb(0,150,219)">></span><span class="pln" style="color:rgb(198,249,131)">true</span><span class="tag" style="color:rgb(0,150,219)"></prop></span></li><li class="L3" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">                </span><span class="tag" style="color:rgb(0,150,219)"><prop</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="atn" style="color:rgb(255,204,51)">key</span><span class="pun" style="color:rgb(204,153,153)">=</span><span class="atv" style="color:rgb(128,255,128)">"hibernate.hbm2ddl.auto"</span><span class="tag" style="color:rgb(0,150,219)">></span><span class="pln" style="color:rgb(198,249,131)">update</span><span class="tag" style="color:rgb(0,150,219)"></prop></span></li><li class="L4" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">            </span><span class="tag" style="color:rgb(0,150,219)"></props></span></li><li class="L5" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">        </span><span class="tag" style="color:rgb(0,150,219)"></property></span></li><li class="L6" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">    </span><span class="tag" style="color:rgb(0,150,219)"></bean></span></li></ol>
Copy after login

如果以上内容有疑问,请先阅读:Eclipse搭建Maven工程集成Spring4+Hibernate5+SpringMVC

4、运行测试

接下来就可以编写对应的Controller、Service和Dao层代码了,因为是基于上面提到的那个工程的,所以这里简单修改就能演示了。

添加代码:

<ol class="linenums" style="padding:0px 0px 0px 10px; margin:0px; border-left-width:30px; border-left-style:solid; border-left-color:rgb(79,54,57); list-style-type:decimal-leading-zero; color:rgb(176,235,231)"><li class="L0" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">    </span><span class="lit" style="color:rgb(128,255,128)">@RequestMapping</span><span class="pun" style="color:rgb(204,153,153)">(</span><span class="str">"/oracle"</span><span class="pun" style="color:rgb(204,153,153)">)</span></li><li class="L1" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">    </span><span class="lit" style="color:rgb(128,255,128)">@ResponseBody</span></li><li class="L2" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">    </span><span class="kwd" style="color:rgb(251,140,105)">public</span><span class="pln" style="color:rgb(198,249,131)"> </span><span class="typ" style="color:rgb(246,105,154)">String</span><span class="pln" style="color:rgb(198,249,131)"> oracleCreateTable</span><span class="pun" style="color:rgb(204,153,153)">(){</span></li><li class="L3" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">        logger</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="pln" style="color:rgb(198,249,131)">trace</span><span class="pun" style="color:rgb(204,153,153)">(</span><span class="str">"oracle"</span><span class="pun" style="color:rgb(204,153,153)">);</span></li><li class="L4" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">        demoService</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="pln" style="color:rgb(198,249,131)">save</span><span class="pun" style="color:rgb(204,153,153)">(</span><span class="str">"anxpp"</span><span class="pun" style="color:rgb(204,153,153)">);</span></li><li class="L5" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">        </span><span class="kwd" style="color:rgb(251,140,105)">return</span><span class="pln" style="color:rgb(198,249,131)"> demoService</span><span class="pun" style="color:rgb(204,153,153)">.</span><span class="pln" style="color:rgb(198,249,131)">findAll</span><span class="pun" style="color:rgb(204,153,153)">();</span></li><li class="L6" style="margin:0px; padding:2px 0px; border-bottom-width:1px; border-bottom-style:dashed; border-bottom-color:rgb(85,85,85)"><span class="pln" style="color:rgb(198,249,131)">    </span><span class="pun" style="color:rgb(204,153,153)">}</span></li></ol>
Copy after login

    运行测试:

    01

    多次请求将多次插入值到数据库,并返回。

5、更多文章

    Oracle 12c Windows安装、介绍及简单使用(图文)

    Oracle 12c 简单的jdbc使用

    Eclipse搭建Maven工程集成Spring4+Hibernate5+SpringMVC

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1657
14
PHP Tutorial
1257
29
C# Tutorial
1230
24
What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

What to do if the oracle log is full What to do if the oracle log is full Apr 12, 2025 am 06:09 AM

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

How to create oracle dynamic sql How to create oracle dynamic sql Apr 12, 2025 am 06:06 AM

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values ​​to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

See all articles