Solved

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

Posted on 2002-04-04
3
138 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hibernate insert example 13 39
American Express @Work site and Java 4 68
IBM TS2900 (3572) Tape Autoloader Java? 12 61
How to log java errors in tomcat 8 24
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

726 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