본문 바로가기
MySql

MySQL 데이터 잘림 : 1 행의 'logo'열에 대한 데이터가 너무 깁니다.

by 베이스 공부 2020. 12. 10.
반응형

MySQL 테이블의 BLOB 열에 사진을 삽입하려고하는데 예외가 발생합니다.

Data too long for column 'logo' at row 1. 

다음은 JDBC입니다.

    int idRestaurant = 42;
    String restoname=  "test";
    String restostatus=  "test";
    InputStream fileContent = getUploadedFile();
    int fileSize = getUploadedFileSize();

    Class.forName("com.mysql.jdbc.Driver");
    try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/resto" , "root" , "" )) {
        PreparedStatement ps = conn.prepareStatement("insert into restaurants (idRestaurant, restaurantName, status, logo) values(?,?,?,?)");
        ps.setInt(1, idRestaurant);
        ps.setString(2, restoname);
        ps.setString(3, restostatus);
        ps.setBinaryStream(4, fileContent, fileSize);
        ps.executeUpdate();
        conn.commit();
    }

이 문제를 어떻게 해결합니까?

 

해결 방법

 

logo 열에 허용 된 것보다 큰 데이터를 삽입하려고합니다.

필요에 따라 다음 데이터 유형을 사용하십시오.

TINYBLOB   :     maximum length of 255 bytes  
BLOB       :     maximum length of 65,535 bytes  
MEDIUMBLOB :     maximum length of 16,777,215 bytes  
LONGBLOB   :     maximum length of 4,294,967,295 bytes  

이 예외를 방지하려면 LONGBLOB 를 사용하십시오.

 

참조 페이지 https://stackoverflow.com/questions/21522875

 

 

반응형

댓글