我想通过“浏览”按钮将图像插入到数据库中。这条线有什么问题,ps.setBlob(l16, inputStream)
?此行每次都显示一个错误。如何将图像插入Java数据库中
我的代码是:
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/hostel_management","root","");
PreparedStatement ps= con.prepareStatement("insert into student_info values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
ps.setString(1, tf1.getText());
ps.setString(2, tf2.getText());
.
.
.
ps.setString(15, tf15.getText());
InputStream inputStream = new FileInputStream(new File(tf16.getText()));
ps.setBlob(16, inputStream);
ps.execute();
JOptionPane.showMessageDialog(null, "Successfully Inserted", "Message", JOptionPane.ERROR_MESSAGE);
con.close();
“此行每次都显示错误”错误消息是什么? – hexafraction
您是否验证过参数顺序? –
尝试'ps.setBlob(16,inputStream,(int)fileLength);' – saka1029