473,387 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Column name or number of supplied values does not match table definition in jsp

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.
Jun 21 '07 #1
4 16950
r035198x
13,262 8TB
Which line number is reported, you can see the data type that failed from the reported line number.
Jun 21 '07 #2
Which line number is reported, you can see the data type that failed from the reported line number.
between ps.setString(7,employee_name); and ps.executeUpdate();
Jun 21 '07 #3
This is just a suggestion. I sometimes come up with the same error only to find that the order of the tables in the database do not match the order in my program. SQL is very sensitive with things like that. Also check that the number of question marks indicated in your program match the number of tables in your database.

Hope this helps.
Jun 21 '07 #4
This is just a suggestion. I sometimes come up with the same error only to find that the order of the tables in the database do not match the order in my program. SQL is very sensitive with things like that. Also check that the number of question marks indicated in your program match the number of tables in your database.

Hope this helps.
Tones of thanks Tripmaker, your is suggestion really helpfull for my coding i followed ur suggestion now i don't get that error and the file is successfully inserted in the datbase.

Thanks once again...

Regards,

V. Prasath
Jun 21 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Thomas Jerkins | last post by:
When I write a create table SQL statement I want to add some information about the column heading of each column. How does the exact syntax for the create table look like (which includes this column...
2
by: me | last post by:
I would like to add an Identity to an existing column in a table using a stored procedure then add records to the table and then remove the identity after the records have been added or something...
8
by: btober | last post by:
I'm finding that column defaults are not being assigned to nulls when I do an insert by way of a an ON INSERT rule on a view. For example, the following script \set ON_ERROR_STOP ON \c...
0
by: tania | last post by:
i have this table in my database: CREATE TABLE FILM( F_ID INT(5) NOT NULL AUTO_INCREMENT, F_TITLE VARCHAR(40) NOT NULL, DIRECTOR_FNAME VARCHAR(20) NOT NULL, DIRECTOR_LNAME VARCHAR(20) NOT NULL,...
5
by: Veeru71 | last post by:
Given a table with an identity column (GENERATED BY DEFAULT AS IDENTITY), is there any way to get the last generated value by DB2 for the identity column? I can't use identity_val_local() as...
1
by: jmarr02s | last post by:
I am trying to change my Amount column Data Type from Integer to Decimal (precision 9 digits, scale 3, that is 6 digits to the left of decimal and 3 digits to the right of decimal. Here is the...
6
by: Hemant Shah | last post by:
Folks, Today, I was exporting a table in one database and then importing it in another database. The table in destination database was missing one column (my mistake while creating the table),...
3
by: madhavi123 | last post by:
Hi All, I have a to insert a set of rows into a table which is on some other server, and that table has an identity column which is also a primary key of that column. I am getting the error...
0
by: jeoffh | last post by:
Background: I am trying to "merge" some attributes into an existing XML column in my MS SQL 2005 database. The general idea is that I have an XML column in a table and I would like to update/delete...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.