【发布时间】:2018-01-05 20:15:51
【问题描述】:
我想将值插入到数据库表中。该表有两列:id 和 image。 id 是自增的 int,图像是 blob 类型。这是我的代码:
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, userName, password);
File imgfile = new File(request.getParameter("img"));
InputStream fin = new FileInputStream(imgfile);
PreparedStatement pre = con.prepareStatement("insert into pictures (image) values(?)");
pre.setBinaryStream(1, fin, imgfile.length());
int done=pre.executeUpdate();
} catch(SQLException | ClassNotFoundException e) {
e.printStackTrace();
}
我检查了数据库,没有插入任何内容。服务器输出:
com.mysql.jdbc.MysqlDataTruncation:数据截断:数据太长 第 1 行的“图像”列
【问题讨论】:
-
很确定
SQLException被你提出并忽略了。 -
改了发现异常
-
你是如何定义列的?是一团吗?
-
它是一个 blob,列大小 65535,如果有帮助的话
-
数据太长 - 可能意味着您对 column1 的定义不正确。
标签: java mysql jdbc insert prepared-statement