我想通過「瀏覽」按鈕將圖像插入到數據庫中。這條線有什麼問題,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