I'm trying upload image to database using Java.
I've used following code to do that work.File file= new File("image.jpg");
FileInputStream fis = new FileInputStream("image.jpg");
String开发者_StackOverflow 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();
But it throws me this error.
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0)
Please help me to solve this problem.
Feels like you have an error at "FileInputStream fis = new FileInputStream(fin);" may be i,m wrong, but what is 'fin'?. you should give that argument to be 'file'. Try doing
FileInputStream fis = new FileInputStream(file);
This might work.
精彩评论