欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2020年08月28日 12:07:30   作者:Zartillery  
這篇文章主要介紹了IDEA連接postgressql數(shù)據(jù)庫操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

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

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

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

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

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

修改 C:\Program Files\PostgreSQL\9.4\data路徑下的 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。

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)
@SpringBootTest
public 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
 */
@Controller
public 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.sql
spring.datasource.initialization-mode=always

運行結(jié)果

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

相關(guān)文章

  • Java源碼解析之TypeVariable詳解

    Java源碼解析之TypeVariable詳解

    這篇文章主要介紹了Java源碼解析之TypeVariable詳解,具有一定參考價值,需要的朋友可以了解下。
    2017-10-10
  • Eclipse、MyEclipse 導(dǎo)入svn項目具體步驟

    Eclipse、MyEclipse 導(dǎo)入svn項目具體步驟

    這篇文章主要介紹了Eclipse、MyEclipse 導(dǎo)入svn項目具體步驟的相關(guān)資料,需要的朋友可以參考下
    2016-10-10
  • SpringMVC多個模塊404報錯問題及解決

    SpringMVC多個模塊404報錯問題及解決

    這篇文章主要介紹了SpringMVC多個模塊404報錯問題及解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • SpringCloud超詳細講解微服務(wù)網(wǎng)關(guān)Zuul基礎(chǔ)

    SpringCloud超詳細講解微服務(wù)網(wǎng)關(guān)Zuul基礎(chǔ)

    這篇文章主要介紹了SpringCloud?Zuul微服務(wù)網(wǎng)關(guān),負(fù)載均衡,熔斷和限流,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-10-10
  • 詳解JAVA設(shè)計模式之適配器模式

    詳解JAVA設(shè)計模式之適配器模式

    這篇文章主要介紹了JAVA設(shè)計模式之適配器模式的的相關(guān)資料,文中示例代碼非常詳細,供大家參考和學(xué)習(xí),感興趣的朋友可以了解
    2020-06-06
  • java 讀寫文件[多種方法]

    java 讀寫文件[多種方法]

    前兩天用到讀寫文件的操作,上網(wǎng)搜了一些這方面的資料。很有用的。
    2008-11-11
  • 詳解Java并發(fā)工具類之CountDownLatch和CyclicBarrier

    詳解Java并發(fā)工具類之CountDownLatch和CyclicBarrier

    在JDK的并發(fā)包中,有幾個非常有用的并發(fā)工具類,它們分別是:CountDownLatch、CyclicBarrier、Semaphore和Exchanger,本文主要來講講其中CountDownLatch和CyclicBarrier的使用,感興趣的可以了解一下
    2023-06-06
  • JAVA實現(xiàn)讀取txt文件內(nèi)容的方法

    JAVA實現(xiàn)讀取txt文件內(nèi)容的方法

    本篇文章主要介紹了JAVA實現(xiàn)讀取txt文件內(nèi)容的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-01-01
  • SpringBoot集成Redis及SpringCache緩存管理示例詳解

    SpringBoot集成Redis及SpringCache緩存管理示例詳解

    本文介紹了如何在SpringBoot中集成Redis并使用SpringCache進行緩存管理,詳解了Redis的配置、使用以及SpringCache的注解,還闡述了SpringCache的工作原理,包括其AOP實現(xiàn)和與各種緩存框架的集成,使得開發(fā)者可以輕松實現(xiàn)緩存功能,以提高應(yīng)用性能
    2024-09-09
  • RestTemplate發(fā)送get和post請求,下載文件的實例

    RestTemplate發(fā)送get和post請求,下載文件的實例

    這篇文章主要介紹了RestTemplate發(fā)送get和post請求,下載文件的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09

最新評論