160929、各数据库连接配置与maven依赖安装

最近做的项目都是maven的,据说maven是个东西。把依赖的jar文件的事情都委托出去辣!试着用了一下哈,效果还可以!

今天做了数据库配置这一块,特意把相关的东西总结出来,以备不时之需。

MySQL

db driver maven dependency

<dependency>
   <groupId>mysql</groupId>
   <artifactId>mysql-connector-java</artifactId>
   <version>5.0.5</version>

</dependency>

 

hibernate.properties

hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://localhost/trails?createDatabaseIfNotExist=true&amp;useUnicode=true&amp;characterEncoding=utf-8
hibernate.connection.username=root
hibernate.connection.password=
hibernate.hbm2ddl.auto=update

Oracle

db driver maven dependency

<dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc14</artifactId>
        <version>10.2.0.2.0</version>
</dependency>

hibernate.properties

hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
hibernate.connection.driver_class=oracle.jdbc.OracleDriver
hibernate.connection.url=jdbc:oracle:thin:@localhost:1521:XE
hibernate.connection.username=system
hibernate.connection.password=system
hibernate.hbm2ddl.auto=update
 
# The Oracle JDBC driver doesn't like prepared statement caching very much.
hibernate.statement_cache.size=0
# or baching with BLOBs very much.
hibernate.jdbc.batch_size=0
 
# After a while, Oracle throws this exception: too many open cursors
# Disable PreparedStatement caching for the connection pool too.
# http://www.hibernate.org/120.html#A10
hibernate.dbcp.ps.maxIdle = 0
 
# Stoping hibernate from using the column-names in queries to retrieve data from the resultsets
# More info in http://www.jroller.com/page/dashorst?entry=hibernate_3_1_something_performance1
hibernate.jdbc.wrap_result_sets=true

SQL Server    

db driver maven dependency

<dependency>

        <groupId>net.sourceforge.jtds</groupId>

        <artifactId>jtds</artifactId>

        <version>1.2</version>

</dependency>

hibernate.properties

hibernate.dialect=org.hibernate.dialect.SQLServerDialect

hibernate.connection.driver_class=net.sourceforge.jtds.jdbc.Driver

hibernate.connection.url=jdbc:jtds:sqlserver://localhost:1433/trails

hibernate.connection.username=sa

hibernate.connection.password=

hibernate.hbm2ddl.auto=update

手动安装Maven依赖包

例如要安装这样一个依赖到maven本地仓库:

1.将此依赖添加到项目的pom.xml

<dependency>

   <groupId>com.microsoft.sqlserver</groupId>

   <artifactId>sqljdbc4</artifactId>

   <version>3.0</version>

</dependency>

2.在命令行中执行install命令

mvn install:install-file -Dfile=sqljdbc4-3.0.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=3.0 -Dpackaging=jar

3.将sqljdbc4-3.0.jar拷贝到此依赖安装目录

将sqljdbc4-3.0.jar拷贝到X:Documents and Settings\%USER%.m2 epositorycommicrosoftsqlserversqljdbc43.0 中即可.

原文地址:https://www.cnblogs.com/zrbfree/p/5955616.html