Spring Boot | Connect Microsoft sql server

It’s really easy to setup datasource in Spring boot irrespective of database used. MS SQL server datasource can be created using JTDS driver from sourceforge.

http://jtds.sourceforge.net



To create  MSSQL server datasource, just add the following properties in the application.properties file –

#application.properties
spring.datasource.url=jdbc:jtds:sqlserver://host:port/dbname;instance=instancename;
spring.datasource.username=username;
spring.datasource.password=password;
spring.datasource.driverClassName=net.sourceforge.jtds.jdbc.Driver

After adding the above properties just auto wire the DataSource and rest spring boot takes care of creating data source and setting in the Java file –

private JdbcTemplate jdbcTemplate;

@Autowired
private void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}




Leave a Reply

Your email address will not be published. Required fields are marked *