自由飛翔

          我在仰望,java之上

          統(tǒng)計

          留言簿(2)

          我關(guān)注的blog

          閱讀排行榜

          評論排行榜

          #

          頁面utf-8,jsp提交中文action中亂碼

              只有注冊用戶登錄后才能閱讀該文。閱讀全文

          posted @ 2011-11-25 15:11 GavinMiao 閱讀(91) | 評論 (0)編輯 收藏

          轉(zhuǎn)載:java斷言Assertion

               摘要: 文章來源:http://www.cnblogs.com/woodslee/articles/165669.html 一、 Assertion的語法和語義J2SE 1.4在語言上提供了一個新特性,就是assertion(斷言)功能,它是該版本在Java語言方面最大的革新。在軟件開發(fā)中,assertion是一種經(jīng)典的調(diào)試、測試方式,本文將深入解析assertion功能的使用以及其設...  閱讀全文

          posted @ 2011-11-25 13:20 GavinMiao 閱讀(785) | 評論 (0)編輯 收藏

          tree和menu控件

          Xtree
          download及demo頁面:http://webfx.eae.net/dhtml/xtree/index.html
          api頁面:
          http://webfx.eae.net/dhtml/xtree/api.html 

          參考文章:
          http://apps.hi.baidu.com/share/detail/45745962
          大量開源menu控件:http://www.open-open.com/ajax/Menu.htm
          easy
          ui Menu及ext tree等;

          posted @ 2011-11-24 15:22 GavinMiao 閱讀(300) | 評論 (0)編輯 收藏

          iframe頁面調(diào)用父頁面的js函數(shù) (轉(zhuǎn)載)


          假若iframe所在的頁面here.html有個JS函數(shù)為:wode(),它位于頁面的<script></script>這個節(jié)

          然后iframe的src,即里面的頁面為:other.html,那么我們在other.html里面就可以如下調(diào)用here.html里面的wode這個函數(shù):window.parent.wode();


          對于父頁面的控件的引用就如法炮制:window.parent.document.getElementById('xxxx')
          來自: http://hi.baidu.com/%D3%DA%EA%BB%CC%ED/blog/item/a8384000e1ddec0f1c9583e6.html

          posted @ 2011-11-24 12:03 GavinMiao 閱讀(829) | 評論 (0)編輯 收藏

          mysql導入導出表結(jié)構(gòu)及表數(shù)據(jù)及執(zhí)行sql文件

          在mysql中執(zhí)行sql文件的命令 : source  d:\myprogram\database\db.sql;
          連接MYSQL:
          mysql -h主機地址 -u用戶名 -p用戶密碼
          修改密碼:
          mysqladmin -u用戶名 -p舊密碼 password 新密碼

          從數(shù)據(jù)庫導出數(shù)據(jù)庫文件:

          1.將數(shù)據(jù)庫mydb導出到e:\MySQL\mydb.sql文件中:

          打開開始->運行->輸入cmd 進入命令行模式

          1. c:\>MySQLdump -h localhost -u root -p mydb >e:\MySQL\mydb.sql 

          然后輸入密碼,等待一會導出就成功了,可以到目標文件中檢查是否成功。

          2.將數(shù)據(jù)庫mydb中的mytable導出到e:\MySQL\mytable.sql文件中:

          1. c:\>MySQLdump -h localhost -u root -p mydb mytable>e:\MySQL\mytable.sql 

          3.將數(shù)據(jù)庫mydb的結(jié)構(gòu)導出到e:\MySQL\mydb_stru.sql文件中:

          1. c:\>MySQLdump -h localhost -u root -p mydb --add-drop-table >e:\MySQL\mydb_stru.sql 

          -h localhost可以省略,其一般在虛擬主機上用

          四.從外部文件MySQL導入數(shù)據(jù)到數(shù)據(jù)庫中:

          從e:\MySQL\mydb2.sql中將文件中的SQL語句導入數(shù)據(jù)庫中:

          1.從命令行進入MySQL,然后用命令CREATE DATABASE mydb2;創(chuàng)建數(shù)據(jù)庫mydb2。

          2.退出MySQL 可以輸入命令exit;或者quit;

          3.在CMD中輸入下列命令:

          1. c:\>MySQL -h localhost -u root -p mydb2 < e:\MySQL\mydb2.sql 

          然后輸入密碼,就OK了。

          五.下面談一下關(guān)于導入文件大小限制問題的解決:

          默認情況下:MySQL導入文件大小有限制的,最大為2M,所以當文件很大時候,直接無法導入,下面就這個問題的解決列舉如下:

          1.在php.ini中修改相關(guān)參數(shù):

          影響MySQL導入文件大小的參數(shù)有三個:

          1. memory_limit=128M,upload_max_filesize=2M,post_max_size=8M 

          修改upload_ ......

          參考文章:
          http://database.51cto.com/art/201005/200739.htm

          posted @ 2011-11-22 10:54 GavinMiao 閱讀(8831) | 評論 (0)編輯 收藏

          轉(zhuǎn)載:解決 java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN 錯誤

          文章來源:http://blog.csdn.net/nickshen3/article/details/1698261 
          ResourceBundle.getBundle("com.cheng.scrap.config") tells the classloader to load a resource named "config" with package "com.cheng.scrap."  Its fully-qualified-resource-name is"com.cheng.scrap.config"


          posted @ 2011-11-17 15:28 GavinMiao 閱讀(3645) | 評論 (0)編輯 收藏

          MyEclipse + Tomcat項目重命名

          文章來源:
          問題描述:
          原來項目名稱是shopping,部署到tomcat后直接輸入地址端口后加項目名http://localhost:8080/shopping就可以瀏覽主頁了,后來我把項目名改成shoppingCar,重新部署到tomcat后發(fā)現(xiàn)部署過去的項目還是shopping而不是shoppingCar
          解決方案:
          在MyEclipse里面只把項目重命名是不行的,還要修改以下內(nèi)容:
          項目→properties→MyEclipse→Web下修改Web Context-root的名字為重命名之后的名字即可。

          posted @ 2011-11-15 15:09 GavinMiao 閱讀(437) | 評論 (0)編輯 收藏

          轉(zhuǎn)載:在項目中使用多個數(shù)據(jù)源-多sessionFactory方案

          適用范圍:適合SSH架構(gòu)訪問多個數(shù)據(jù)庫,數(shù)據(jù)庫的類型和表結(jié)構(gòu)不必相同,且沒有跨庫事務的情況(跨庫事務最好用分布式事務處理)。

          文章來源:http://apps.hi.baidu.com/share/detail/15756344

          實現(xiàn)方式:我們可以在spring的配置文件中配置多個sessionFactory,如:
          <bean id="aDataSource"
             class="org.apache.commons.dbcp.BasicDataSource"
             destroy-method="close">
             <property name="driverClassName">
              <value>${adriver}</value>
             </property>
             <property name="url">
              <value>${aurl}</value>
             </property>
             <property name="username">
              <value>${ausername}</value>
             </property>
             <property name="password">
              <value>${apassword}</value>
             </property>
          </bean>
          <bean id="bDataSource"
             class="org.apache.commons.dbcp.BasicDataSource"
             destroy-method="close">
             <property name="driverClassName">
              <value>${bdriver}</value>
             </property>
             <property name="url">
              <value>${burl}</value>
             </property>
             <property name="username">
              <value>${busername}</value>
             </property>
             <property name="password">
              <value>${bpassword}</value>
             </property>
          </bean>
          <bean id="cDataSource"
             class="org.apache.commons.dbcp.BasicDataSource"
             destroy-method="close">
             <property name="driverClassName">
              <value>${cdriver}</value>
             </property>
             <property name="url">
              <value>${curl}</value>
             </property>
             <property name="username">
              <value>${cusername}</value>
             </property>
             <property name="password">
              <value>${cpassword}</value>
             </property>
          </bean>

           

          <!-- Hibernate SessionFactorys -->
          <bean id="aSessionFactory"
             class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
             <property name="dataSource">
              <ref local="aDataSource" />
             </property>
             <property name="mappingResources">
              <list>
               <value>
                .hbm.xml文件
               </value>
              </list>
             </property>
             <property name="hibernateProperties">
              <props>
               <prop key="hibernate.dialect">
                ${ahibernate.dialect}
               </prop>
               <prop key="hibernate.show_sql">true</prop>
               <prop key="format_sql">true</prop>
              </props>
             </property>
          </bean>

          <bean id="bSessionFactory"
             class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
             <property name="dataSource">
              <ref local="bDataSource" />
             </property>
             <property name="mappingResources">
              <list>
               <value>
                .hbm.xml文件
               </value>
              </list>
             </property>
             <property name="hibernateProperties">
              <props>
               <prop key="hibernate.dialect">
                ${bhibernate.dialect}
               </prop>
               <prop key="hibernate.show_sql">true</prop>
               <prop key="format_sql">true</prop>
              </props>
             </property>
          </bean>

          <bean id="cSessionFactory"
             class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
             <property name="dataSource">
              <ref local="cDataSource" />
             </property>
             <property name="mappingResources">
              <list>
               <value>
                 .hbm.xml文件
               </value>
              </list>
             </property>
             <property name="hibernateProperties">
              <props>
               <prop key="hibernate.dialect">
                ${chibernate.dialect}
               </prop>
               <prop key="hibernate.show_sql">true</prop>
               <prop key="format_sql">true</prop>
              </props>
             </property>
          </bean>

          <bean id="sessionFactory" class="com.cintel.dcp.datasource.MultiSessionFactory">
             <property name="sessionFactory"><ref local="aSessionFactory"/></property>
          </bean>
          注意:最后一個com.cintel.dcp.datasource.MultiSessionFactory要自己實現(xiàn),它實現(xiàn)了SessionFactory接口和ApplicationContext接口,如下:
          package com.cintel.dcp.datasource;

          import java.io.Serializable;
          import java.sql.Connection;
          import java.util.Map;
          import java.util.Set;

          import javax.naming.NamingException;
          import javax.naming.Reference;

          import org.apache.commons.logging.Log;
          import org.apache.commons.logging.LogFactory;
          import org.hibernate.HibernateException;
          import org.hibernate.Interceptor;
          import org.hibernate.SessionFactory;
          import org.hibernate.StatelessSession;
          import org.hibernate.classic.Session;
          import org.hibernate.engine.FilterDefinition;
          import org.hibernate.metadata.ClassMetadata;
          import org.hibernate.metadata.CollectionMetadata;
          import org.hibernate.stat.Statistics;
          import org.springframework.beans.factory.NoSuchBeanDefinitionException;
          import org.springframework.context.ApplicationContext;
          import org.springframework.context.ApplicationContextAware;

          public class MultiSessionFactory implements SessionFactory, ApplicationContextAware {
          private static final long serialVersionUID = 2064557324203496378L;
          private static final Log log = LogFactory.getLog(MultiSessionFactory.class);
          private ApplicationContext applicationContext = null;
          private SessionFactory sessionFactory = null;

          public ApplicationContext getApplicationContext() {
             return applicationContext;
          }

          public void setApplicationContext(ApplicationContext applicationContext) {
             this.applicationContext = applicationContext;
          }

          public SessionFactory getSessionFactory(String sessionFactoryName) {
             log.debug("sessionFactoryName:"+sessionFactoryName);
             try{
              if(sessionFactoryName==null||sessionFactoryName.equals("")){
               return sessionFactory;
              }
              return (SessionFactory)this.getApplicationContext().getBean(sessionFactoryName);
             }catch(NoSuchBeanDefinitionException ex){
              throw new RuntimeException("There is not the sessionFactory <name:"+sessionFactoryName+"> in the applicationContext!");
             }
          }

          public SessionFactory getSessionFactory() {
             String sessionFactoryName = CustomerContextHolder.getCustomerType();
             return getSessionFactory(sessionFactoryName);
          }

          public void setSessionFactory(SessionFactory sessionFactory) {
             this.sessionFactory = sessionFactory;
          }


          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#close()
          */
          public void close() throws HibernateException {
             getSessionFactory().close();
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#evict(java.lang.Class)
          */
          public void evict(Class persistentClass) throws HibernateException {
             getSessionFactory().evict(persistentClass);
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#evict(java.lang.Class, java.io.Serializable)
          */
          public void evict(Class persistentClass, Serializable id) throws HibernateException {
             getSessionFactory().evict(persistentClass, id);
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#evictCollection(java.lang.String)
          */
          public void evictCollection(String roleName) throws HibernateException {
             getSessionFactory().evictCollection(roleName);
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#evictCollection(java.lang.String, java.io.Serializable)
          */
          public void evictCollection(String roleName, Serializable id) throws HibernateException {
             getSessionFactory().evictCollection(roleName, id);
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#evictEntity(java.lang.String)
          */
          public void evictEntity(String entityName) throws HibernateException {
             getSessionFactory().evictEntity(entityName);
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#evictEntity(java.lang.String, java.io.Serializable)
          */
          public void evictEntity(String entityName, Serializable id) throws HibernateException {
             getSessionFactory().evictEntity(entityName, id);
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#evictQueries()
          */
          public void evictQueries() throws HibernateException {
             getSessionFactory().evictQueries();
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#evictQueries(java.lang.String)
          */
          public void evictQueries(String cacheRegion) throws HibernateException {
             getSessionFactory().evictQueries(cacheRegion);
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#getAllClassMetadata()
          */
          public Map getAllClassMetadata() throws HibernateException {
             return getSessionFactory().getAllClassMetadata();
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#getAllCollectionMetadata()
          */
          public Map getAllCollectionMetadata() throws HibernateException {
             return getSessionFactory().getAllCollectionMetadata();
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#getClassMetadata(java.lang.Class)
          */
          public ClassMetadata getClassMetadata(Class persistentClass) throws HibernateException {
             return getSessionFactory().getClassMetadata(persistentClass);
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#getClassMetadata(java.lang.String)
          */
          public ClassMetadata getClassMetadata(String entityName) throws HibernateException {
             return getSessionFactory().getClassMetadata(entityName);
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#getCollectionMetadata(java.lang.String)
          */
          public CollectionMetadata getCollectionMetadata(String roleName) throws HibernateException {
             return getSessionFactory().getCollectionMetadata(roleName);
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#getCurrentSession()
          */
          public Session getCurrentSession() throws HibernateException {
             return getSessionFactory().getCurrentSession();
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#getDefinedFilterNames()
          */
          public Set getDefinedFilterNames() {
             return getSessionFactory().getDefinedFilterNames();
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#getFilterDefinition(java.lang.String)
          */
          public FilterDefinition getFilterDefinition(String filterName) throws HibernateException {
             return getSessionFactory().getFilterDefinition(filterName);
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#getStatistics()
          */
          public Statistics getStatistics() {
             return getSessionFactory().getStatistics();
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#isClosed()
          */
          public boolean isClosed() {
             return getSessionFactory().isClosed();
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#openSession()
          */
          public Session openSession() throws HibernateException {
             return getSessionFactory().openSession();
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#openSession(java.sql.Connection)
          */
          public Session openSession(Connection connection) {
             return getSessionFactory().openSession(connection);
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#openSession(org.hibernate.Interceptor)
          */
          public Session openSession(Interceptor interceptor) throws HibernateException {
             return getSessionFactory().openSession(interceptor);
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#openSession(java.sql.Connection, org.hibernate.Interceptor)
          */
          public Session openSession(Connection connection, Interceptor interceptor) {
             return getSessionFactory().openSession(connection, interceptor);
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#openStatelessSession()
          */
          public StatelessSession openStatelessSession() {
             return getSessionFactory().openStatelessSession();
          }
          /* (non-Javadoc)
          * @see org.hibernate.SessionFactory#openStatelessSession(java.sql.Connection)
          */
          public StatelessSession openStatelessSession(Connection connection) {
             return getSessionFactory().openStatelessSession(connection);
          }
          /* (non-Javadoc)
          * @see javax.naming.Referenceable#getReference()
          */
          public Reference getReference() throws NamingException {
             return getSessionFactory().getReference();
          }
          }


          然后我用一個常量類來標識sessionFactory
          public class DynamicDataSourceType {
          public static final String A= "aSessionFactory";
          public static final String B= "bSessionFactory";
          public static final String C= "cSessionFactory";
          }

          最后一個關(guān)鍵類:用來存放當前正在使用的sessionFactory
          public class CustomerContextHolder {

          private static final ThreadLocal contextHolder = new ThreadLocal();

          public static void setCustomerType(String customerType) {
             Assert.notNull(customerType, "customerType cannot be null");
             contextHolder.set(customerType);
          }

          public static String getCustomerType() {
             return (String) contextHolder.get();
          }

          public static void clearCustomerType() {
             contextHolder.remove();
          }
          }

          可以在action、service、dao中進行數(shù)據(jù)庫切換,切換方式:
          CustomerContextHolder.setCustomerType(DynamicDataSourceType.A);

          以上思路來自javaEye論壇的一個高手,在此標識感謝

          posted @ 2011-11-14 16:11 GavinMiao 閱讀(860) | 評論 (0)編輯 收藏

          轉(zhuǎn)載:動態(tài)切換數(shù)據(jù)源(spring+hibernate)

          文章來源:

          起因:在當前我手上的一個項目中需要多個數(shù)據(jù)源,并且來自于不同類型的數(shù)據(jù)庫... 因為很多歷史原因.這個項目的住數(shù)據(jù)源是MySQL,整個系統(tǒng)的CURD都是操作的這個數(shù)據(jù)庫.

          但是還有另外兩個用于數(shù)據(jù)采集的數(shù)據(jù)庫: MSSQL,ACCESS.還好只是用于數(shù)據(jù)采集,在事務上可以不要跨數(shù)據(jù)庫了,這一點節(jié)省了好多的工作量.環(huán)境:我搭建的測試環(huán)境是 spring2.5.6+hibernate3.2
          思路:動態(tài)切換數(shù)據(jù)源確切的來說是在同一類型數(shù)據(jù)庫的情況下的。意思就是說 , 在系統(tǒng)中的使用的數(shù)據(jù)庫分布在多臺數(shù)據(jù)庫服務器或者在同臺服務器上的多個數(shù)據(jù)庫. 在運行時期間根據(jù)某種標識符來動態(tài)的選擇當前操作的數(shù)據(jù)庫.     1.數(shù)據(jù)源是相同類型的數(shù)據(jù)庫: 一個SessionFactory+動態(tài)數(shù)據(jù)源+一個事務管理器     2.數(shù)據(jù)源是不同類型的數(shù)據(jù)庫: 根據(jù)類型 配置多套SessionFactory模擬:兩個mysql數(shù)據(jù)源+一個Access數(shù)據(jù)源
          實現(xiàn)
          1.切換數(shù)據(jù)源需要標識符,標識符是Object類型
          package lhp.example.context;
          public enum DBType {
          dataSource1, dataSource2;
          }

          2.然后創(chuàng)建一個用于切換數(shù)據(jù)源(設置或者獲得上下文)的工具類
          package lhp.example.context;

          public class ContextHolder {
          private static final ThreadLocal<Object> holder = new ThreadLocal<Object>();

          public static void setDbType(DBType dbType) {
          holder.set(dbType);
          }

          public static DBType getDbType() {
          return (DBType) holder.get();
          }

          public static void clearDbType() {
          holder.remove();
          }
          }

          3.創(chuàng)建動態(tài)數(shù)據(jù)源類,繼承org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource這個類.
          package lhp.example.context;

          import java.util.logging.Logger;

          import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

          public class DynamicDataSource extends AbstractRoutingDataSource {
          public static final Logger logger = Logger.getLogger(DynamicDataSource.class.toString());

          @Override
          protected Object determineCurrentLookupKey() {
          DBType key = ContextHolder.getDbType();//獲得當前數(shù)據(jù)源標識符
          //logger.info("當前數(shù)據(jù)源 :" + key);
          return key;
          }

          }

          4.然后配置多個數(shù)據(jù)源
          <!-- 數(shù)據(jù)源1 : mysql -->
          <bean id="dataSource1" class="com.mchange.v2.c3p0.ComboPooledDataSource">
          <property name="driverClass" value="com.mysql.jdbc.Driver" />
          <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1:3306/dec" />
          <property name="user" value="root" />
          <property name="password" value="" />
          </bean>
          <!-- 數(shù)據(jù)源2 : mysql -->
          <bean id="dataSource2" class="com.mchange.v2.c3p0.ComboPooledDataSource">
          <property name="driverClass" value="com.mysql.jdbc.Driver" />
          <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1:3306/lms" />
          <property name="user" value="root" />
          <property name="password" value="" />
          </bean>

          <!-- 數(shù)據(jù)源3 : access -->
          <bean id="dataSource3" class="com.mchange.v2.c3p0.ComboPooledDataSource">
          <property name="driverClass" value="sun.jdbc.odbc.JdbcOdbcDriver" />
          <property name="jdbcUrl" value="jdbc:odbc:accessTest" />
          <property name="user" value="administrator" />
          <property name="password" value="XLZX0309" />
          </bean>

          <!-- mysql 動態(tài)數(shù)據(jù)源設置-->
          <bean id="mysqlDynamicDataSource" class="lhp.example.context.DynamicDataSource">
          <property name="targetDataSources">
          <!-- 標識符類型 -->
          <map key-type="lhp.example.context.DBType">
          <entry key="dataSource1" value-ref="dataSource1" />
          <entry key="dataSource2" value-ref="dataSource2" />
          </map>
          </property>
          <property name="defaultTargetDataSource" ref="dataSource1" />
          </bean>

          5.配置sessionFactory
          <!-- mysql sessionFactory -->
          <bean id="mysqlSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
          <property name="dataSource" ref="mysqlDynamicDataSource" />
          <property name="hibernateProperties">
          <props>
          <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
          <prop key="hibernate.show_sql">true</prop>
          <prop key="hibernate.hbm2ddl.auto">update</prop><!--create validate -->
          <prop key="hibernate.query.substitutions">true 1, false 0</prop>
          </props>
          </property>
          </bean>

          <!-- access sessionFactory -->
          <bean id="aceessSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
          <property name="dataSource" ref="dataSource3" />
          <property name="hibernateProperties">
          <props>
          <!-- access 語法和MSSQL相似 所以用的MSSQL方言,或者可以使用第三方方言 -->
          <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
          <prop key="hibernate.jdbc.batch_size">30</prop>
          <prop key="hibernate.jdbc.fetch_size">50</prop>
          <prop key="hibernate.show_sql">true</prop>
          <prop key="hibernate.format_sql">false</prop>
          <prop key="hibernate.hbm2ddl.auto">update</prop><!--create validate -->
          <prop key="hibernate.query.substitutions">true 1, false 0</prop>
          <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
          <!-- <prop key="hibernate.cache.use_second_level_cache">true</prop> -->
          <!-- <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> -->
          <!-- <prop key="hibernate.cache.use_query_cache">true</prop> -->
          <!-- <prop key="hibernate.generate_statistics">true</prop> -->
          <!-- <prop key="hibernate.cache.provider_configuration_file_resource_path">classpath:ehcache.xml</prop> -->
          </props>
          </property>
          </bean>

          6.測試用例
          package lhp.example.junit;

          import static org.junit.Assert.*;
          import java.sql.DatabaseMetaData;
          import lhp.example.context.ContextHolder;
          import lhp.example.context.DBType;
          import org.hibernate.Session;
          import org.hibernate.SessionFactory;
          import org.junit.Before;
          import org.junit.Test;
          import org.springframework.context.ApplicationContext;
          import org.springframework.context.support.ClassPathXmlApplicationContext;

          public class ServiceTest {
          private ApplicationContext context;
          //三個數(shù)據(jù)源的URL
          private String dataSource1_URL = "jdbc:mysql://127.0.0.1:3306/dec";
          private String dataSource2_URL = "jdbc:mysql://127.0.0.1:3306/lms";
          private String dataSource3_URL = "jdbc:odbc:accessTest";
          private SessionFactory mysqlSessionFactory;
          private SessionFactory aceessSessionFactory;

          @Before
          public void setUp() throws Exception {
          // 選擇數(shù)據(jù)源初始化spring
          ContextHolder.setDbType(DBType.dataSource1);
          //
          String[] xmlFiles = new String[] {
          "applicationContext-dataSource.xml",
          "applicationContext-hibernate.xml",
          "applicationContext-spring.xml" };
          //
          context = new ClassPathXmlApplicationContext(xmlFiles);
          //
          mysqlSessionFactory = (SessionFactory) context.getBean("mysqlSessionFactory");
          aceessSessionFactory = (SessionFactory) context.getBean("aceessSessionFactory");
          }

          @SuppressWarnings("deprecation")
          @Test
          public void mysqlDataSourceTest() {
          try {

          Session mysqlSession = mysqlSessionFactory.openSession();
          // 獲得數(shù)據(jù)庫元數(shù)據(jù)
          DatabaseMetaData meatData = mysqlSession.connection().getMetaData();

          // 默認啟動數(shù)據(jù)源 dataSource1
          //斷言當前數(shù)據(jù)源URL是否是dataSource1的URL
          assertEquals(dataSource1_URL, meatData.getURL());

          // 切換到數(shù)據(jù)源 dataSource2
          ContextHolder.setDbType(DBType.dataSource2);
          mysqlSession = mysqlSessionFactory.openSession();
          meatData = mysqlSession.connection().getMetaData();
          //斷言當前數(shù)據(jù)源URL是否是dataSource2的URL
          assertEquals(dataSource2_URL, meatData.getURL());

          } catch (Exception e) {
          e.printStackTrace();
          }
          }

          @SuppressWarnings("deprecation")
          @Test
          public void accessDataSourceTest() {
          try {
          Session accessSession = aceessSessionFactory.openSession();
          // 獲得數(shù)據(jù)庫元數(shù)據(jù)
          DatabaseMetaData meatData = accessSession.connection().getMetaData();
          //斷言當前數(shù)據(jù)源URL是否是dataSource3的URL
          assertEquals(dataSource3_URL, meatData.getURL());


          } catch (Exception e) {
          e.printStackTrace();
          }
          }

          }

          posted @ 2011-11-14 15:37 GavinMiao 閱讀(799) | 評論 (0)編輯 收藏

          liunx版本查詢、創(chuàng)建用戶及用戶組

          1.liunx版本查詢:
          lsb_release -a或者
           cat /etc/issue或者
          cat /etc/redhat-release 
          2.
          創(chuàng)建用戶

          useradd
          -u  uid,例如:500
          -G  附加組
          -g  主要組 
          -d  家目錄 /home/mysql
          -s  默認登錄shell 例如:/bin/bash
          eg:useradd -u 500 -g majorGroup -G  minorGroup -d  /home/username -s /bin/bash USERNAME
          userdel -r(連同家目錄一起刪了)
          eg2:useradd -g mysql  -d  /home/test -s /bin/bash test
          3.創(chuàng)建組:groupadd

          posted @ 2011-11-10 12:08 GavinMiao 閱讀(331) | 評論 (0)編輯 收藏

          僅列出標題
          共14頁: 上一頁 1 2 3 4 5 6 7 8 9 下一頁 Last 
          主站蜘蛛池模板: 葫芦岛市| 外汇| 文登市| 丰镇市| 甘孜| 阳朔县| 酉阳| 施甸县| 平凉市| 阿勒泰市| 滨州市| 新泰市| 上犹县| 兴国县| 秦皇岛市| 博罗县| 陆川县| 宁津县| 淮北市| 海城市| 清河县| 鄂温| 堆龙德庆县| 五大连池市| 界首市| 怀仁县| 大冶市| 黑龙江省| 丹凤县| 调兵山市| 枝江市| 秦安县| 石楼县| 景德镇市| 彰化市| 康保县| 宁津县| 湘乡市| 茶陵县| 巢湖市| 盘山县|