SachiraChin
SachiraChin

Reputation: 570

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

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 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.

Upvotes: 1

Views: 1301

Answers (1)

Kris
Kris

Reputation: 8873

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.

Upvotes: 1

Related Questions