Hibernate加载其数据库配置

本文详细介绍了Hibernate配置文件的结构与设置,包括如何配置不同数据库连接及其对应的方言,展示了通过修改配置文件实现灵活切换数据库的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

     Hibernate加载其配置文件hibernate.properties和hibernate.cfg.xml,常用xml文件比较直观,方便管理, Hibernate 是一个流行的开源对象关系映射工具,方便连接不同数据库,更换数据库,只要修改Hibernate配置文件,大度减少项目的维护。
     完整的配置如下:
<? 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 >

        
<!--  Database connection settings  -->
        
< property  name ="connection.driver_class" > org.hsqldb.jdbcDriver </ property >
        
< property  name ="connection.url" > jdbc:hsqldb:hsql://localhost /test</ property >
        
< property  name ="connection.username" > sa </ property >
        
< property  name ="connection.password" ></ property >

        
<!--  JDBC connection pool (use the built-in)  -->
        
< property  name ="connection.pool_size" > 1 </ property >

        
<!--  SQL dialect  -->
        
< property  name ="dialect" > org.hibernate.dialect.HSQLDialect </ property >

        
<!--  Enable Hibernate's automatic session context management  -->
        
< property  name ="current_session_context_class" > thread </ property >

        
<!--  Disable the second-level cache   -->
        
< property  name ="cache.provider_class" > org.hibernate.cache.NoCacheProvider </ property >

        
<!--  Echo all executed SQL to stdout  -->
        
< property  name ="show_sql" > true </ property >

        
<!--  Drop and re-create the database schema on startup  -->
        
< property  name ="hbm2ddl.auto" > create </ property >

        
< mapping  resource ="../*.hbm.xml" />

    
</ session-factory >

</ hibernate-configuration >
     常用数据库连接
     MySql 3/4/5:
   < property  name ="dialect" > org.hibernate.dialect.MySQLDialect </ property >
  

   <
property  name ="connection.driver_class" > com.mysql.jdbc.Driver </ property >
  
< property  name ="connection.url" > jdbc:mysql://localhost:3306/test </ property >     
  
< property  name ="connection.username" > root </ property >
  
< property  name ="connection.password" > </property>
    Microsoft SQLServer (via jTDS):
   < property  name ="dialect" > org.hibernate.dialect.SQLServerDialect </ property >
  

   <
property  name ="connection.driver_class" > net.sourceforge.jtds.jdbc.Driver </ property >
  
< property  name ="connection.url" > jdbc:jtds:sqlserver://localhost:1433/test;useCursors=true </ property >     
  
< property  name ="connection.username" > sa </ property >
  
< property  name ="connection.password" ></ property >   
    IBM DB2:
   < property  name ="dialect" > org.hibernate.dialect.DB2Dialect </ property >
  

   <
property  name ="connection.driver_class" > com.ibm.db2.jcc.DB2Driver </ property >
  
< property  name ="connection.url" > jdbc:db2://localhost:50000/test </ property >     
  
< property  name ="connection.username" > db2inst1 </ property >
  
< property  name ="connection.password" ></ property >  
    Oracle:
   < property  name ="dialect" > org.hibernate.dialect.OracleDialect </ property >
  

   <
property  name ="connection.driver_class" > oracle.jdbc.driver.OracleDriver </ property >
  
< property  name ="connection.url" > jdbc:oracle:thin:@localhost:1521:test </ property >     
  
< property  name ="connection.username" > ora </ property >
  
< property  name ="connection.password" ></ property >
    Informix:
   < property  name ="dialect" > org.hibernate.dialect.InformixDialect </ property >
  

   <
property  name ="connection.driver_class" > com.informix.jdbc.IfxDriver </ property >
  
< property  name ="connection.url" > jdbc:informix-sqli://localhost:1526/test:informixserver=server1 </ property >     
  
< property  name ="connection.username" > root </ property >
  
< property  name ="connection.password" ></ property >   
  
< property  name ="connection.encoding" > true </ property >
    Sybase (via jTDS):
   < property  name ="dialect" > org.hibernate.dialect.SybaseDialect </ property >
  
   < property  name ="connection.driver_class" > net.sourceforge.jtds.jdbc.Driver </ property >
  
< property  name ="connection.url" > jdbc:jtds:sybase://localhost:7100/test;useCursors=true </ property >     
  
< property  name ="connection.username" > root </ property >
  
< property  name ="connection.password" ></ property >
    PostgreSQL:
   < property  name ="dialect" > org.hibernate.dialect.PostgreSQLDialect </ property >
  
   < property  name ="connection.driver_class" > org.postgresql.Driver </ property >
  
< property  name ="connection.url" > jdbc:postgresql://localhost:5432/test </ property >     
  
< property  name ="connection.username" > root </ property >
  
< property  name ="connection.password" ></ property >
    MaxDB(SAPDB):
   < property  name ="dialect" > org.hibernate.dialect.SAPDBDialect </ property >
  
   < property  name ="connection.driver_class" > com.sap.dbtech.jdbc.DriverSapDB </ property >
  
< property  name ="connection.url" > jdbc:sapdb://localhost/test </ property >     
  
< property  name ="connection.username" > root </ property >
  
< property  name ="connection.password" ></ property >
   
138282.html

forker 2007-08-21 10:01 发表评论
基于Spring Boot搭建的一个多功能在线学习系统的实现细节。系统分为管理员和用户两个主要模块。管理员负责视频、文件和文章资料的管理以及系统运营维护;用户则可以进行视频播放、资料下载、参与学习论坛并享受个性化学习服务。文中重点探讨了文件下载的安全性和性能优化(如使用Resource对象避免内存溢出),积分排行榜的高效实现(采用Redis Sorted Set结构),敏感词过滤机制(利用DFA算法构建内存过滤树)以及视频播放的浏览器兼容性解决案(通过FFmpeg调整MOOV原子位置)。此外,还提到了权限管理面自定义动态加载器的应用,提高了系统的灵活性和易用性。 适合人群:对Spring Boot有一定了解,希望深入理解其实际应用的技术人员,尤其是从事在线教育平台开发的相关从业者。 使用场景及目标:适用于需要快速搭建稳定高效的在线学习平台的企业或团队。目标在于提供一套完整的解决案,涵盖从资源管理到用户体验优化等多个面,帮助开发者更好地理解和掌握Spring Boot框架的实际运用技巧。 其他说明:文中不仅提供了具体的代码示例和技术思路,还分享了许多实践经验教训,对于提高项目质量有着重要的指导意义。同时强调了安全性、性能优化等面的重要性,确保系统能够应对大规模用户的并发访问需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值