- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 41133 个
- 通用积分
- 2.0023
- 学术水平
- 7 点
- 热心指数
- 5 点
- 信用等级
- 5 点
- 经验
- 2201 点
- 帖子
- 198
- 精华
- 1
- 在线时间
- 36 小时
- 注册时间
- 2015-6-1
- 最后登录
- 2024-3-3
|
- Connecting to a database
- In this recipe, we will connect to a MySQL or PostgreSQL database from a Spring application.
- To connect to another database system, go to http://www.oxygenxml.com/database_
- drivers.html to find the relevant dependencies, driver class, and URL type.
- Getting ready
- You need a MySQL or PostgreSQL database up and running.
- How to do it…
- Here are the steps to connect from a Spring application to an existing database:
- 1. Add the Maven dependency for Spring JDBC in pom.xml:
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-jdbc</artifactId>
- <version>4.1.6.RELEASE</version>
- </dependency>
- 2. If you're using MySQL, add its Maven dependency in pom.xml:
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.1.35</version>
- </dependency>
- 3. If you're using PostgreSQL, add its Maven dependency in pom.xml:
- <dependency>
- <groupId>postgresql</groupId>
- <artifactId>postgresql</artifactId>
- <version>9.1-901-1.jdbc4</version>
- </dependency>
复制代码
|
|