Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
javabyranjith committed Mar 21, 2020
1 parent 6747582 commit afa5d71
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 92 deletions.
12 changes: 12 additions & 0 deletions sboot-jdbc-mysql/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.gradle/
gradle/
.settings/
target/
bin/
build/
**/META-INF/**
.sts4-cache


.project
.classpath
10 changes: 10 additions & 0 deletions sboot-jdbc-mysql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### TOOLS & TECHNOLOGIES
1. Eclipse/STS
2. Java 1.8
3. MySQL

### CONCEPTS/TOPICS COVERED
1. JDBC CRUD operations

### HOW TO RUN?
1. Run As Boot Application
1 change: 1 addition & 0 deletions sboot-jdbc-mysql/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-jdbc')
runtime('org.springframework.boot:spring-boot-devtools')
implementation 'org.projectlombok:lombok'
runtime('mysql:mysql-connector-java')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package jbr.spring.boot;
package jbr.sboot;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import jbr.spring.boot.service.ProductService;
import jbr.sboot.service.ProductService;
import lombok.extern.slf4j.Slf4j;

@SpringBootApplication
@Slf4j
public class SpringBootJdbcMysqlApplication implements CommandLineRunner {
private static final Logger log = LoggerFactory.getLogger(SpringBootJdbcMysqlApplication.class);

@Autowired
ProductService productService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jbr.spring.boot.dao;
package jbr.sboot.dao;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -9,19 +9,19 @@
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import jbr.spring.boot.model.Product;
import jbr.sboot.model.Product;
import lombok.extern.slf4j.Slf4j;

@Repository
@Slf4j
public class ProductDao {

private static final Logger log = LoggerFactory.getLogger(ProductDao.class);

@Autowired
JdbcTemplate jdbcTemplate;

public void addProduct() {
log.info("add prod start");

jdbcTemplate.execute("INSERT INTO product VALUES('100','Samsung S8', 'Mobile', '75000')");
jdbcTemplate.execute("INSERT INTO product VALUES('200','Usha Fan', 'Fan', '6000')");
jdbcTemplate.execute("INSERT INTO product VALUES('300','Dell Vostro', 'Laptop', '79000')");
Expand All @@ -30,7 +30,7 @@ public void addProduct() {
public List<Product> getAllProducts() {
List<Product> products = new ArrayList<>();
jdbcTemplate.query("SELECT * FROM product", new Object[] {},
(rs, row) -> new Product(rs.getString("id"), rs.getString("name"), rs.getString("type"), rs.getString("price")))
(rs, row) -> new Product(rs.getInt("id"), rs.getString("name"), rs.getString("category"), rs.getString("price")))
.forEach(products::add);

return products;
Expand Down
19 changes: 19 additions & 0 deletions sboot-jdbc-mysql/src/main/java/jbr/sboot/model/Product.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package jbr.sboot.model;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Product {
private Integer id;
private String name;
private String category;
private String price;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package jbr.spring.boot.service;
package jbr.sboot.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import jbr.spring.boot.dao.ProductDao;
import jbr.spring.boot.model.Product;
import jbr.sboot.dao.ProductDao;
import jbr.sboot.model.Product;

@Service
public class ProductService {
Expand Down
54 changes: 0 additions & 54 deletions sboot-jdbc-mysql/src/main/java/jbr/spring/boot/model/Product.java

This file was deleted.

8 changes: 0 additions & 8 deletions sboot-jdbc-mysql/src/main/resources/application.properties

This file was deleted.

8 changes: 8 additions & 0 deletions sboot-jdbc-mysql/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
server:
port: 6060

spring:
datasource:
url: jdbc:mysql://localhost:3306/springboot
username: root
password: ranjith driver-class-name: com.mysql.jdbc.Driver
Expand Down
2 changes: 2 additions & 0 deletions sboot-jdbc-mysql/src/main/resources/sql-scripts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE DATABASE IF NOT EXISTS springboot;
CREATE TABLE springboot.product (id INTEGER, name VARCHAR(20), category VARCHAR(30), price VARCHAR(10));

This file was deleted.

0 comments on commit afa5d71

Please sign in to comment.