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

 

About Author

Author Image
Murari Kumar

Murari is a bright Web developer. He has expertise in Java.

Request for Proposal

Name is required

Comment is required

Sending message..