博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
利用maven 下依赖包
阅读量:5281 次
发布时间:2019-06-14

本文共 5330 字,大约阅读时间需要 17 分钟。

在做Java Web项目的时候,不可避免的就要使用到数据库,下面就是在IDEA中添加mysql依赖的方法。 如果你看到这里,就表示你弄懂了IDEA,maven和Tomcat等,所以... 只需要在pom.xml中添加依赖就可以了,下面是我的配置文件。

4.0.0 com.suixue example 1.0-SNAPSHOT

junit junit 4.11 jar test

org.springframework spring-context 4.1.6.RELEASE jar log4j log4j 1.2.17 jar

com.fasterxml.jackson.core jackson-core 2.2.1

com.fasterxml.jackson.core jackson-databind 2.1.3

com.fasterxml.jackson.core jackson-annotations 2.1.2 mysql mysql-connector-java 5.1.25 红色区域就是添加mysql依赖的代码哦,若版本不一样,可以再version中进行更改。 添加依赖后,IDEA就会自动为我们下载需要的jar包了哦!

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

 

各种数据库Hibernate链接配置

Derby

db driver maven dependency
<
dependency
>
        
<
groupId
>org.apache.derby</
groupId
>
        
<
artifactId
>derbyclient</
artifactId
>
        
<
version
>10.2.2.0</
version
>
</
dependency
>
hibernate.properties
hibernate.dialect=org.hibernate.dialect.DerbyDialect
hibernate.connection.driver_class=org.apache.derby.jdbc.ClientDriver
hibernate.connection.url=jdbc:derby:
//localhost/trails;create=true
hibernate.connection.username=any
hibernate.connection.password=value
hibernate.hbm2ddl.auto=update

 MySQL

MySQL throws an EOFException when the database connection has been closed after the lease has expired, but it works again on subsequent requests.

There is a reported issue with DBCP and the MySQL driver. Check the JIRA issue for more info and a possible solution

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

H2

db driver maven dependency
<
dependency
>
        
<
groupId
>com.h2database</
groupId
>
        
<
artifactId
>h2</
artifactId
>
        
<
version
>1.0.20070304</
version
>
</
dependency
>
hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.connection.driver_class=org.h2.Driver
hibernate.connection.url=jdbc:h2:trails
hibernate.connection.username=sa
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

PostgreSQL.

db driver maven dependency
<
dependency
>
        
<
groupId
>postgresql</
groupId
>
        
<
artifactId
>postgresql</
artifactId
>
        
<
version
>8.2-504.jdbc3</
version
>
</
dependency
>
hibernate.properties
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.connection.driver_class=org.postgresql.Driver
hibernate.connection.url=jdbc:postgresql:
//localhost/trails
hibernate.connection.username=postgres
hibernate.connection.password=postgres
hibernate.hbm2ddl.auto=update

Microsoft 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

HSQLDB 

db driver maven dependency
<
dependency
>
        
<
groupId
>hsqldb</
groupId
>
        
<
artifactId
>hsqldb</
artifactId
>
        
<
version
>1.8.0.7</
version
>
</
dependency
>
hibernate.properties
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.connection.url=jdbc:hsqldb:trails;shutdown=
true
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\repository\com\microsoft\sqlserver\sqljdbc4\3.0 中即可.

转载于:https://www.cnblogs.com/sundaysjava/p/10317717.html

你可能感兴趣的文章
java获取hostIp和hostName
查看>>
关于web服务器和数据库的各种说法(搜集到的)
查看>>
C# Stream 和 byte[] 之间的转换
查看>>
OMG: daily scrum nine
查看>>
redis与spring结合错误情况
查看>>
第六章 字节码执行方式--解释执行和JIT
查看>>
字符串方法title()、istitle()
查看>>
yield语句
查看>>
查看linux系统中占用cpu最高的语句
查看>>
[洛谷P1738]洛谷的文件夹
查看>>
ubuntu server设置时区和更新时间
查看>>
【京东咚咚架构演进】-- 好文收藏
查看>>
【HTML】网页中如何让DIV在网页滚动到特定位置时出现
查看>>
文件序列化
查看>>
jQuery之end()和pushStack()
查看>>
Bootstrap--响应式导航条布局
查看>>
Learning Python 009 dict(字典)和 set
查看>>
JavaScript中随着鼠标拖拽而移动的块
查看>>
HDU 1021 一道水题
查看>>
The operation couldn’t be completed. (LaunchServicesError error 0.)
查看>>