亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術(shù)文章
文章詳情頁

IDEA連接postgressql數(shù)據(jù)庫操作

瀏覽:4日期:2024-08-16 10:31:46

打開IDEA后選擇Database數(shù)據(jù)庫選項卡

IDEA連接postgressql數(shù)據(jù)庫操作

點擊加號標(biāo)志,選擇Data Source,在彈出選項中選擇PostgreSQL數(shù)據(jù)庫

IDEA連接postgressql數(shù)據(jù)庫操作

填入配置信息,點擊Test Connection按鈕測試是否連接成功,然后點擊ok

IDEA連接postgressql數(shù)據(jù)庫操作

補充知識:IDEA spring boot 連接Postgresql配置 【已解決】

1.IDEA創(chuàng)建項目

IDEA連接postgressql數(shù)據(jù)庫操作

IDEA連接postgressql數(shù)據(jù)庫操作

修改 C:Program FilesPostgreSQL9.4data路徑下的 pg_hba.conf配置信息

# METHOD can be 'trust', 'reject', 'md5', 'password', 'gss', 'sspi',# 'ident', 'peer', 'pam', 'ldap', 'radius' or 'cert'. Note that# 'password' sends passwords in clear text; 'md5' is preferred since# it sends encrypted passwords.

這里解釋了配置信息,我們只需要將自己電腦ipv4/ipv6對應(yīng)的 METHOD修改成trust就可以使用。我的電腦采用的ipv4,所以我修改的是ipv4的METHOD為trust。

IDEA連接postgressql數(shù)據(jù)庫操作

2.創(chuàng)建application.yml文件,寫入驅(qū)動接口

spring: datasource: url: jdbc:postgresql://172.30.105.178:5432/mysql?useSSL=false username: postgres password: 0000 driverClassName: org.postgresql.Driver

JpaPostgresqlApplicationTests.java

package com.qingsong.jdbc_test;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.test.context.SpringBootTest;import org.springframework.test.context.junit4.SpringRunner;import javax.sql.DataSource;import java.sql.Connection;import java.sql.SQLException;@RunWith(SpringRunner.class)@SpringBootTestpublic class JdbcTestApplicationTests { @Autowired DataSource dataSource; @Test public void contextLoads() throws SQLException { System.out.println('連接成功'); System.out.println('dataSource.getClass()內(nèi)容***'+dataSource.getClass()); Connection connection = dataSource.getConnection(); System.out.println('connection內(nèi)容***'+connection); connection.close(); }}

controller.java

package com.qingsong.mybatis_mysql.control;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.jdbc.core.JdbcTemplate;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.ResponseBody;import java.util.List;import java.util.Map;/** * @Auther: 青松 * @Date: 2019/3/5 20:19 */@Controllerpublic class controller { /** * @Autowired 注釋,它可以對類成員變量、方法及構(gòu)造函數(shù)進行標(biāo)注,完成自動裝配的工作。 通過 @Autowired的使用來消除 set ,get方法。 * 在使用@Autowired之前,我們對一個bean配置起屬性時,是這用的 */ @Autowired JdbcTemplate jdbcTemplate; @ResponseBody @GetMapping('/hi') public Map<String,Object> map(){ List<Map<String,Object>> list=jdbcTemplate.queryForList('select * from author'); return list.get(0); }}

Author.sql

create table Author( code varchar(20) primary key, name varchar(20) not null);

application.properties

# schema.sql中一般存放的是DDL腳本spring.datasource.schema=classpath:Author.sqlspring.datasource.initialization-mode=always

運行結(jié)果

IDEA連接postgressql數(shù)據(jù)庫操作

以上這篇IDEA連接postgressql數(shù)據(jù)庫操作就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: IDEA
相關(guān)文章:
主站蜘蛛池模板: 欧美黄色大片在线观看 | 亚洲精品香蕉一区二区 | 午夜精品久视频在线观看 | 在线碰碰视频在线观看 | 青青草在线免费观看 | 亚洲精品久久久久久下一站 | 免费观看a毛片一区二区不卡 | 久久er热视频在这里精品 | 91精品乱码一区二区三区 | 国产美女啪啪 | 成人小视频在线免费观看 | 婷婷精品在线 | 亚洲欧美另类国产 | 免费精品精品国产欧美在线 | 九月婷婷开心九月 | 国产超级碰碰在线公开视频 | 精品一区二区三区视频在线观看 | 在线观看国产精美视频 | 一级毛片在线播放免费 | 我想看黄色毛片 | 91精品国产91久久综合 | 簧片在线免费看 | 嫩草影院麻豆久久视频 | 国产一区中文字幕 | aaa毛片视频免费观看 | 131美女爱做免费高清视频 | 国产精品视频免费的 | 欧美亚洲网| 免费一级a毛片在线播放视 免费一级a毛片免费观看欧美大片 | 日本人一级大毛片 | 欧美日韩你懂的 | 欧美精品国产制服第一页 | 国产精品偷伦视频免费手机播放 | 国产一级毛片午夜福 | 日韩一级欧美一级在线观看 | 久久久在线视频精品免费观看 | 国产无限免费观看黄网站 | 黄色综合网站 | 一级特级全黄 | 黄色一级在线 | 免费看黄资源大全高清 |