我正在尝试使用 Java 将图像上传到数据库。
我使用以下代码来完成这项工作。
File file= new File("image.jpg");
FileInputStream fis = new FileInputStream("image.jpg");
String query = "insert into mytable(id,image) values(?, ?)";
PreparedStatement stmt = dbConn.prepareStatement(query);
stmt.setInt(1, sid);
stmt.setBinaryStream(2, fis, (int) file.length());
stmt.executeUpdate();
但是它抛出了这个错误。
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0)
请帮我解决这个问题。
最佳答案
感觉你在“FileInputStream fis = new FileInputStream(fin);”处出错了可能我错了,但什么是“鳍”?您应该将该参数设为"file"。 尝试做
FileInputStream fis = new FileInputStream(文件);
这可能有效。
关于java.sql.SQLException : Parameter index out of range (1 > number of parameters, 为 0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7329414/