java mac postgresql_PostgreSQL 的安装与使用 for mac
##安裝 在 mac 下,可以利用 homebrew 直接安裝 PostgreSQL:
brew install postgresql
安裝好之后有一個數(shù)據(jù)庫(postgres),如需要重新初始化數(shù)據(jù)庫:
initdb /usr/local/var/postgres_mao
啟動:
pg_ctl -D /usr/local/var/postgres -l logfile start
關(guān)閉:
pg_ctl -D /usr/local/var/postgres stop -s -m fast
##與jpa的整合 build.gradle
compile("org.postgresql:postgresql:9.4-1206-jdbc42")
application.yml
spring:
datasource:
data: classpath*:data.sql
url: jdbc:postgresql://localhost:5432/postgres
username: username
password: 123456
driverClassName: org.postgresql.Driver
jpa:
show-sql: true
database: POSTGRESQL
hibernate.ddl-auto: create-drop
ps:關(guān)于spring.jpa.hibernate.ddl-auto配置,出門右轉(zhuǎn)(http://my.oschina.net/maomaolsm/blog/740017)
DAO中主鍵需要使用數(shù)據(jù)庫IDENTITY
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
ps:@GeneratedValue的設(shè)置,出門左轉(zhuǎn)(http://my.oschina.net/maomaolsm/blog/740015)
否則,數(shù)據(jù)庫文件中插入數(shù)據(jù)需要加上id
INSERT INTO person (id,name) VALUES (1,'maomao');
總結(jié)
以上是生活随笔為你收集整理的java mac postgresql_PostgreSQL 的安装与使用 for mac的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微型计算机上的南桥芯片功能,微型计算机及
- 下一篇: 如何修改操作系统运行服务器,如何设置Bi