Solved

Database and Servlets To Msterjev (Values in my Database for the insertion problem )

Posted on 2002-04-04
3
137 Views
Last Modified: 2013-11-24
OrderNumber = autonumber;
ItemCode = text;
Category = text;

and all the other fields have a text value except the currency . There are 8fields and I only want to send 6 of them to the database and leave 2(i.e. OrderNumber,Status )



>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
I still have a problem with the insertion of other values where the primary key is auto number in the database. The thing is if I assign as below I get the message

You tried to assign the Null value to a variable that is not a Variant data type.

AND


If I leave them blank this is what I get

Syntax error in INSERT INTO statement.

but the insertin part is OKay right.

Could you please help with the sample code of doing this.


String SQL = "INSERT INTO KeepOrdersTable ItemCode,OrderNumber,Category,AnimalType,AgeGroup,UnitPrice,Quantity,Status VALUES(?,?,?,?,?,?,?,?)";

try{

 PreparedStatement  stmt = conn.prepareStatement(SQL) ;

       stmt.setString(1,  null);
        stmt.setString(2,  ItemCode);
        stmt.setString(3,  Category);
        stmt.setString(4,  AnimalType);
        stmt.setString(5,  AgeGroup);
        stmt.setString(6,  UnitPrice);
        stmt.setString(7,  Quantity);
        stmt.setString(8,  null);

       stmt.executeUpdate();

}

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
0
Comment
Question by:wbmorapedi
3 Comments
 
LVL 3

Expert Comment

by:msterjev
ID: 6917592
Coud you send the database field description:
For example:

field1: integer; default value: 0;

etc.

The rule is you never insert autoincrement primary key field (I've alredy answered this question to you). Open MS Access and if you want some field to accept null values check it (but you never send null values into the INSERT statements, just omit this field from INSERT statement). Or, specify some default value for some field if you don't want to use this field into INSERT statement.

DON'T SEND null VALUES INTO THE INSERT STATEMENT!
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 6917919
>DON'T SEND null VALUES INTO THE INSERT STATEMENT!

Curious as to why not?  I think I do that someplaces without problems.. but I use setNull method.

CJ
0
 
LVL 4

Accepted Solution

by:
pellep earned 50 total points
ID: 6919628
String SQL = "INSERT INTO KeepOrdersTable ItemCode,OrderNumber,Category,AnimalType,AgeGroup,UnitPrice,Quantity,Status
VALUES(?,?,?,?,?,?,?,?)";

should be

String SQL = "INSERT INTO KeepOrdersTable (ItemCode,OrderNumber,Category,AnimalType,AgeGroup,UnitPrice,Quantity,Status)
VALUES(?,?,?,?,?,?,?,?)";

apart from that, I agree with cheekycj and msterjev. I'd like to know which JDBC driver/database you're using that allows
- null values in inserts
- including identity fields (OrderNumber) in the insert statement

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question