0% found this document useful (0 votes)
14 views3 pages

SBMS 6am 25012023

Uploaded by

maharanarajib441
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

SBMS 6am 25012023

Uploaded by

maharanarajib441
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Date : 25-01-2023

Spring Boot and Microservices


6AM | Mr. Raghu | (ASHOK IT)
---------------------------------------------------------------------
LOB: Large OBjects : Complex data can be stored as a File in database
[File Pointers] Ex: Word Document, Excel file, PPT, PDF, Images..etc

These are two types: (DataType)


BLOB : Binary Large OBject (PDF, Word, Images)
CLOB : Character Large OBject (Lengthy Text , ex: Notes: 1000 Chars data)

*) Now a days, Cloud Buckets are used to store data for LOBs.
Ex: AWS S3 (Simple Storage Service) Buckets.

==> These are standard names given by SQL (also followed by few databases)
BLOB = byte[] + @Lob (JPA)
CLOB = char[] + @Lob

*) We can use free cloud services like : imgbb upload


and store its URL in DB Column.
String imgUrl= "https://i.ibb.co/kmX9MqC/iphone14pro.png"

=======Ex==========================================================
1. YAML
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/boot6am
username: root
password: root
jpa:
database-platform: org.hibernate.dialect.MySQL8Dialect
show-sql: true
hibernate:
ddl-auto: update

2. Entity
package com.app.raghu.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name="prodtab")
public class Product {
@Id
@Column(name="pid")
private Integer prodId;
@Column(name="pcode")
private String prodCode;
@Column(name="pcost")
private Double prodCost;

@Lob //BLOB
@Column(name="pimg")
private byte[] prodImg;

@Lob //CLOB
@Column(name="pdsc")
private char[] prodDesc;
}

3. Repository interface
package com.app.raghu.repo;

import org.springframework.data.jpa.repository.JpaRepository;

import com.app.raghu.entity.Product;

public interface ProductRepository


extends JpaRepository<Product, Integer> {

4. Runner class
package com.app.raghu.runner;

import java.io.FileInputStream;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import com.app.raghu.entity.Product;
import com.app.raghu.repo.ProductRepository;

@Component
public class ProductRunner implements CommandLineRunner {

@Autowired
private ProductRepository repo;

public void run(String... args) throws Exception {


FileInputStream fis = new FileInputStream("D:/images/iphone14pro.png");
byte[] barr = new byte[fis.available()];
fis.read(barr);

String input ="HEllo welcome ?! How are you ? where are you..
congrats ... text me when you see this message...............";
char[] carr = input.toCharArray();

Product p = new Product(101, "IPhone", 6500.0, barr, carr);

repo.save(p);

fis.close();
}

}
==========================================
Commit
Rollback
ACID Properties
==========================================

You might also like