반응형
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
반응형
'MySql' 카테고리의 다른 글
MySQL Phpstorm. SSH 터널을 통해 mysql 서버에 액세스 할 수 없음 (외부 호스트에 의해 연결이 닫힘) (0) | 2020.12.11 |
---|---|
MySQL dql을 사용하여 데이터 테이블에서 고유 값을 얻는 방법은 무엇입니까? (0) | 2020.12.11 |
MySQL에서 이름 설정 utf8? (0) | 2020.12.10 |
MySQL 여러 테이블의 데이터를 dataGridView에 표시하는 방법 (0) | 2020.12.10 |
MySQL 열을 AUTO_INCREMENT로 변경 (0) | 2020.12.10 |
댓글