473,406 Members | 2,208 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,406 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 16951
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.