Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wrong insert order into MySQL, why?

Status
Not open for further replies.

olsmor

Programmer
Feb 5, 2004
2
NO
We have MySQL 4.0.17, mySQL Connector/J 3.0.10 and J2EE 1.3.1 installed on our server. When inserting values from a CMP Entity Bean the column order ends up alphabeticly inside mySQL.

Here is our insert-query:

INSERT INTO kunde (kundenr, firmaetternavn, fornavn, badresse, bpostnr, bpoststed, padresse, ppostnr, ppoststed, telefon, faks, epost) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)

Here is our kunde-table:

Kunde(kundenr, firmaetternavn, fornavn, badresse, bpostnr, bpoststed, padresse, ppostnr, ppoststed, telefon, faks, epost)

After a insert-query the kunde-table looks like this:

KUNDENR FIRMAETTERNAVN FORNAVN etc.
----------------------------------------------------------------------------
[badresse-value] [bpostnr-value] [bpostste-value] etc.
[badresse-value] [bpostnr-value] [bpostste-value] etc.


Does anyone know what could be the cause of this problem!
Sorry for my bad english.

 
If your question implies that the data is not in the order in which you inserted it, this is normal. A relational database is not ordered -- it is a mathematical set of pieces of information.

If you wish the data to be ordered on retrieval, you must specify the order using an "ORDER BY" clause in your SELECT query.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
No, that's not what I'm pointing to. The problem is that the column kundenr doesn't contain [kundenr-values] but [badresse-values] after an insert-query.

Even if our insert-query is in the same order as the columns in the database:
INSERT INTO kunde (kundenr, firmaetternavn, fornavn, badresse, bpostnr, bpoststed, padresse, ppostnr, ppoststed, telefon, faks, epost) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)

Thanks for helping me
 
Sorry. I understand now.

I have never seen a circumstance with MySQL where the data does anywhere but the column to which it is specified. I recommend that you examine the queries you are using to insert the data to make sure they are formed as they should be.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top