开发者

java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0)

开发者 https://www.devze.com 2023-04-03 08:12 出处:网络
I\'m trying upload image to database using Java. I\'ve used following code to do that work. File file= new File(\"image.jpg\");

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号