Solved

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

Posted on 2002-04-04
3
136 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java - Why doesn't this JFrame work 3 60
Java string replace 11 48
Java Restore security prompts not working 10 16
going to wrong jsp page 2 22
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

832 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