Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2002-04-04
3
Medium Priority
?
141 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 150 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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.
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…
This video teaches viewers about errors in exception handling.
Suggested Courses

636 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