首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

筹建SSH框架链接Oracle数据库

2013-03-28 
搭建SSH框架链接Oracle数据库public class UserLogin extends ActionSupport{public String login(){Syste

搭建SSH框架链接Oracle数据库

public class UserLogin extends ActionSupport{public String login(){System.out.println("经过了");return SUCCESS;}}
ClassPath下的struts.xml

<?xml version="1.0" encoding="UTF-8"?>  <!DOCTYPE hibernate-configuration PUBLIC               "-//Hibernate/Hibernate Configuration DTD 3.0//EN"               "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">  <hibernate-configuration>      <session-factory>          <property name="connection.driver_class">              oracle.jdbc.driver.OracleDriver        </property>          <property name="connection.url">             jdbc:oracle:thin:@localhost:1521:orcl        </property>          <!--  数据库连接设置 -->          <property name="eclipse.connection.profile">oracle</property>          <property name="connection.username">weibo</property>          <property name="connection.password">weibo</property>          <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>          <!-- show_sql 生成SQL语句 -->          <property name="show_sql">true</property>      <property name="defaultAutoCommit">true</property> <!-- oracle特有的提交更改 -->        <!-- SQL dialect 方言 -->          <property name="hibernate.dialect">              org.hibernate.dialect.Oracle9Dialect          </property>          <!-- 添加实体类的映射文件-->          <mapping resource="com/struts/model/Student.hbm.xml" />                      <!-- Annotation方式配置          <mapping class="entity.Login"/>           -->      </session-factory>  </hibernate-configuration>  

在classpath下建立applicationContext-hibernate.xml

 注:以下代码中的dataSource没有用到。大家也可以试试LocalSessionFactoryBean的另外一个构造函数。这个我不多说大家去看API或者源码

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"      xmlns:aop="http://www.springframework.org/schema/aop"      xmlns:tx="http://www.springframework.org/schema/tx"      xsi:schemaLocation="      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">    <!-- 配置dataSource start --><bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">    <property name="driverClass" value="oracle.jdbc.driver.OracleDriver" />          <property name="jdbcUrl"              value="jdbc:oracle:thin:@localhost:1521:orcl" />          <property name="user" value="weibo" />          <property name="password" value="weibo" />          <property name="minPoolSize" value="2" />          <property name="maxPoolSize" value="50" />          <property name="initialPoolSize" value="10" />          <property name="maxIdleTime" value="60" />          <property name="acquireIncrement" value="2" />  </bean>     <!-- 配置dataSource end --><!-- 配置sessionFactory start-->  <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">    <property name="configLocation">             <value>classpath:/hibernate.cfg.xml</value>         </property>   </bean><!-- 配置sessionFactory end--><!-- 配置hibernateTemplate -->  <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">      <property name="sessionFactory" ref="sessionFactory"></property>  </bean></beans>
加入hibernateTemplate的注入
<bean id="UserLogin" class="com.struts.action.UserLogin">        <property name="hibernateTemplate" ref="hibernateTemplate"></property></bean>
修改UserLogin类


源码打包下载:

    http://pan.baidu.com/share/link?shareid=403237&uk=1997312776



热点排行