Dear All,
Can anybody help me about my coding, i'm inserting the image file to database using jsp. When i execute the code, the following error is occurred:
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Insert Error: Column name or number of supplied values does not match table definition.
I'm using MS-SQL Server.
My code is:
[<%@ page language="java" import="java.sql.*,java.io.*,java.util.Date,java.t ext.*" contentType="text/html" %>
<%!
Connection con;
Statement st;
ResultSet rs;
PreparedStatement ps;
%>
<%
String file_path, category, description, file_name, employee_name="ram, employee_id;
float image_size;
int product_id=10;
file_path=request.getParameter("image_path");
category=request.getParameter("image_category");
description=request.getParameter("image_descriptio n");
File f = new File(file_path);
FileInputStream fis = new FileInputStream(f);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:cvb");
try
{
ps = con.prepareStatement("insert into products values(?,?,?,?,?,?,?)");
ps.setInt(1,product_id);
ps.setString(2,category);
ps.setString(3,description);
ps.setBinaryStream(4,fis,(int)f.length());
ps.setString(5,f.getName());
ps.setLong(6,f.length());
ps.setString(7,employee_name);
ps.executeUpdate();
out.println("Successfully inserted");
}
catch(Exception e)
{
out.println("Error"+e);
}
%>
]
the datatype of prdocuts table is
1. int
2. varchar
3. varchar
4. Image
5. varchar
6. float
7. varchar
what i did wrong in my coding?
Thanks in advance,
V. Prasath.