Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
347 views
in Technique[技术] by (71.8m points)

java - Import data from mysql workbench to H2

I'm trying to import data from mysql workbench to H2 and I got this error.

CREATE TABLE `jobs` (
  `id` int NOT NULL AUTO_INCREMENT,
  `engjob` varchar(45) NOT NULL,
  `itajob` varchar(45) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=116 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci [42001-200] 42001/42001

which I am not sure why.
I would also like to ask if h2 is the right database to use. I'm trying to create a windows application using java with an embedded database.
Initially I used mySql workbench(mistake on my part). I'm currently trying to move all the data to H2 because I was told it might be easier this way but if you would like to suggest something different so I can make an application with an embedded database that would be helpful too.

thank you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

H2 and other standard-compliant DBMS expect something like

CREATE TABLE "JOBS" (
  "ID" INT GENERATED BY DEFAULT AS IDENTITY (START WITH 116),
  "ENGJOB" VARCHAR(45) NOT NULL,
  "ITAJOB" VARCHAR(45) NOT NULL,
  PRIMARY KEY ("ID")
)

But you're trying to execute non-standard MySQL-style SQL.


Actually current H2 accepts your non-standard definition in MySQL compatibility mode, but you need to compile H2 from its current sources (available on GitHub, building instructions are here) and enable this compatibility mode; these improvements weren't released yet.


Alternatively can simply remove all extra clauses after parentheses and use H2 1.4.200, but you may need its MySQL compatibility mode too: https://h2database.com/html/features.html#compatibility

In that case don't forget to restart the sequence with an additional command:

ALTER TABLE `jobs` ALTER COLUMN `id` RESTART WITH 116;

If you will have more questions about exceptions in SQL, please include the error message and the stack trace. In this question I see only the error code (42001-200), for more complex cases additional information may be needed.


There are three well-known pure Java embedded DBMS and neither of them can be used as drop-in replacement of MySQL.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...