Integrate postgresql with spring boot
Posted By : Murari Kumar | 31-May-2016
In this blog I am going to describe how to establish connection with postgresql using spring boot.
Step-1:
We need to define all information of postgresql like username,password,drivername,url into properties file like this:-
db.name=bitcoinexchange
.db.auth.user= postgres
db.auth.pass= root
#DataBase Driver name
db.driver=org.postgresql.Driver
#DataBase port
db.port=5432
#DataBase host ip
db.ip=127.0.0.1
Step-2:
Now we need to read all the information from properties file and we need write following code which is given below:-
@Component public class Datasource { @Bean public DataSource dataSource() DriverManagerDataSource dataSource = new DriverManagerDataSource() dataSource.setDriverClassName(“DriverName”); dataSource.setUrl("jdbc:postgresql://"+ip address+":"+configuration.DBPort+"/"+DBName); dataSource.setUsername(“userName”); dataSource.setPassword(“Password”); return dataSource;
I hope this will be help u all .
THANKS
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Murari Kumar
Murari is a bright Web developer. He has expertise in Java.