oracle连接maven,各数据库连接maven配置

Derby

db driver maven dependency

org.apache.derby

derbyclient

10.2.2.0

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 solutionhttp://jira.codehaus.org/browse/TRAILS-85

db driver maven dependency

mysql

mysql-connector-java

5.0.5

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&useUnicode=true&characterEncoding=utf-8

hibernate.connection.username=root

hibernate.connection.password=

hibernate.hbm2ddl.auto=update

H2

db driver maven dependency

com.h2database

h2

1.0.20070304

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

com.oracle

ojdbc14

10.2.0.2.0

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 awhile, Oraclethrows this exception: too many open cursors

# Disable PreparedStatement cachingfor 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

postgresql

postgresql

8.2-504.jdbc3

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

net.sourceforge.jtds

jtds

1.2

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

hsqldb

hsqldb

1.8.0.7

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配置

标签:iss   epo   extern   idle   double   comm   sel   panel   .com

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉 本文系统来源:http://www.cnblogs.com/kluan/p/6010110.html

如果你要在本地没有Oracle数据库的情况下,使用Maven构建的Java项目连接远程的Oracle数据库,可以按照以下步骤操作: 1. **添加依赖**: 首先,在你的`pom.xml`文件中添加JDBC驱动依赖。对于Oracle数据库,你需要`ojdbc8`或更高版本的驱动: ```xml <dependencies> <dependency> <groupId>com.oracle.database.jdbc</groupId> <artifactId>ojdbc8</artifactId> <version>21.7.0.2</version> <!-- 最新版本号 --> </dependency> </dependencies> ``` 2. **配置数据库连接信息**: 在你的Java代码中(通常在`DataSource`配置类或者Spring配置文件中),创建一个`Properties`对象存储数据库连接的详细信息,包括URL、用户名、密码等: ```java Properties props = new Properties(); props.setProperty("url", "jdbc:oracle:thin:@<your_host>:<port>:<service_name>"); props.setProperty("username", "<your_username>"); props.setProperty("password", "<your_password>"); ``` 将 `<your_host>`、`<port>` 和 `<service_name>` 替换为实际的数据库地址。 3. **连接池** (可选): 如果你想处理并发连接并提高性能,可以使用如HikariCP或DBCP这样的连接池库,比如HikariCP: ```xml <dependency> <groupId>com.zaxxer</groupId> <artifactId>HikariCP</artifactId> <version>4.0.3</version> </dependency> ``` 然后在代码中初始化连接池: ```java HikariConfig config = new HikariConfig(); config.setJdbcUrl(props.getProperty("url")); config.setUsername(props.getProperty("username")); config.setPassword(props.getProperty("password")); HikariDataSource ds = new HikariDataSource(config); ``` 4. **数据访问**: 使用JDBC API或者Spring Data JPA等框架进行SQL查询或其他数据库操作。 5. **异常处理**: 提供适当的错误处理机制,例如`SQLException`可能会抛出,需要捕获并处理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值