Skip to content

Commit afa5d71

Browse files
committed
up
1 parent 6747582 commit afa5d71

File tree

12 files changed

+65
-92
lines changed

12 files changed

+65
-92
lines changed

sboot-jdbc-mysql/.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.gradle/
2+
gradle/
3+
.settings/
4+
target/
5+
bin/
6+
build/
7+
**/META-INF/**
8+
.sts4-cache
9+
10+
11+
.project
12+
.classpath

sboot-jdbc-mysql/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
### TOOLS & TECHNOLOGIES
2+
1. Eclipse/STS
3+
2. Java 1.8
4+
3. MySQL
5+
6+
### CONCEPTS/TOPICS COVERED
7+
1. JDBC CRUD operations
8+
9+
### HOW TO RUN?
10+
1. Run As Boot Application

sboot-jdbc-mysql/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dependencies {
2828
compile('org.springframework.boot:spring-boot-starter-web')
2929
compile('org.springframework.boot:spring-boot-starter-jdbc')
3030
runtime('org.springframework.boot:spring-boot-devtools')
31+
implementation 'org.projectlombok:lombok'
3132
runtime('mysql:mysql-connector-java')
3233
testCompile('org.springframework.boot:spring-boot-starter-test')
3334
}

sboot-jdbc-mysql/src/main/java/jbr/spring/boot/SpringBootJdbcMysqlApplication.java renamed to sboot-jdbc-mysql/src/main/java/jbr/sboot/SpringBootJdbcMysqlApplication.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
package jbr.spring.boot;
1+
package jbr.sboot;
22

3-
import org.slf4j.Logger;
4-
import org.slf4j.LoggerFactory;
53
import org.springframework.beans.factory.annotation.Autowired;
64
import org.springframework.boot.CommandLineRunner;
75
import org.springframework.boot.SpringApplication;
86
import org.springframework.boot.autoconfigure.SpringBootApplication;
97

10-
import jbr.spring.boot.service.ProductService;
8+
import jbr.sboot.service.ProductService;
9+
import lombok.extern.slf4j.Slf4j;
1110

1211
@SpringBootApplication
12+
@Slf4j
1313
public class SpringBootJdbcMysqlApplication implements CommandLineRunner {
14-
private static final Logger log = LoggerFactory.getLogger(SpringBootJdbcMysqlApplication.class);
1514

1615
@Autowired
1716
ProductService productService;

sboot-jdbc-mysql/src/main/java/jbr/spring/boot/dao/ProductDao.java renamed to sboot-jdbc-mysql/src/main/java/jbr/sboot/dao/ProductDao.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package jbr.spring.boot.dao;
1+
package jbr.sboot.dao;
22

33
import java.util.ArrayList;
44
import java.util.List;
@@ -9,19 +9,19 @@
99
import org.springframework.jdbc.core.JdbcTemplate;
1010
import org.springframework.stereotype.Repository;
1111

12-
import jbr.spring.boot.model.Product;
12+
import jbr.sboot.model.Product;
13+
import lombok.extern.slf4j.Slf4j;
1314

1415
@Repository
16+
@Slf4j
1517
public class ProductDao {
1618

17-
private static final Logger log = LoggerFactory.getLogger(ProductDao.class);
18-
1919
@Autowired
2020
JdbcTemplate jdbcTemplate;
2121

2222
public void addProduct() {
2323
log.info("add prod start");
24-
24+
2525
jdbcTemplate.execute("INSERT INTO product VALUES('100','Samsung S8', 'Mobile', '75000')");
2626
jdbcTemplate.execute("INSERT INTO product VALUES('200','Usha Fan', 'Fan', '6000')");
2727
jdbcTemplate.execute("INSERT INTO product VALUES('300','Dell Vostro', 'Laptop', '79000')");
@@ -30,7 +30,7 @@ public void addProduct() {
3030
public List<Product> getAllProducts() {
3131
List<Product> products = new ArrayList<>();
3232
jdbcTemplate.query("SELECT * FROM product", new Object[] {},
33-
(rs, row) -> new Product(rs.getString("id"), rs.getString("name"), rs.getString("type"), rs.getString("price")))
33+
(rs, row) -> new Product(rs.getInt("id"), rs.getString("name"), rs.getString("category"), rs.getString("price")))
3434
.forEach(products::add);
3535

3636
return products;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package jbr.sboot.model;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
import lombok.NoArgsConstructor;
6+
import lombok.Setter;
7+
import lombok.ToString;
8+
9+
@Getter
10+
@Setter
11+
@AllArgsConstructor
12+
@NoArgsConstructor
13+
@ToString
14+
public class Product {
15+
private Integer id;
16+
private String name;
17+
private String category;
18+
private String price;
19+
}

sboot-jdbc-mysql/src/main/java/jbr/spring/boot/service/ProductService.java renamed to sboot-jdbc-mysql/src/main/java/jbr/sboot/service/ProductService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package jbr.spring.boot.service;
1+
package jbr.sboot.service;
22

33
import java.util.List;
44

55
import org.springframework.beans.factory.annotation.Autowired;
66
import org.springframework.stereotype.Service;
77

8-
import jbr.spring.boot.dao.ProductDao;
9-
import jbr.spring.boot.model.Product;
8+
import jbr.sboot.dao.ProductDao;
9+
import jbr.sboot.model.Product;
1010

1111
@Service
1212
public class ProductService {

sboot-jdbc-mysql/src/main/java/jbr/spring/boot/model/Product.java

Lines changed: 0 additions & 54 deletions
This file was deleted.

sboot-jdbc-mysql/src/main/resources/application.properties

Lines changed: 0 additions & 8 deletions
This file was deleted.

sboot-jdbc-mysql/src/main/resources/application.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
server:
2+
port: 6060
3+
4+
spring:
5+
datasource:
6+
url: jdbc:mysql://localhost:3306/springboot
7+
username: root
8+
password: ranjith driver-class-name: com.mysql.jdbc.Driver
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE DATABASE IF NOT EXISTS springboot;
2+
CREATE TABLE springboot.product (id INTEGER, name VARCHAR(20), category VARCHAR(30), price VARCHAR(10));

sboot-jdbc-mysql/src/test/java/jbr/spring/boot/SpringBootJdbcMysqlApplicationTests.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)