【发布时间】:2014-02-26 16:11: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();
}
我该如何解决这个问题?
【问题讨论】:
-
你有三个选择来解决这个问题。 1. 增加列数据类型的大小。 2. 减小插入该列的内容的大小。 3. 不要插入信息。