Custom table ID generated by java and id generated by java
The following ID must be generated:
56d7ade1-87d1-4f54-8dc8-13611c8c2545
27181ad4-4214-4e12-af3a-911a0103a12f
24cafdfb-eac3-4567-80c0-70d21d096b19
C92046a0-3d94-4d72-ba8f-cdac30ed69e8
1e607dde-eef6-49ac-a3b1-16ba1475d293
In java, you can use the following code:
UUID uuid = UUID. randomUUID ();
System. out. println (uuid. toString ());
How does JAVA code generate an ID based on the ID rules in the table? A similar piece of code
Set automatic growth in SQL Server. The step size is 1.
Do not insert the ID value when inserting.
For example:
The my_table table has fields: id (primary key auto-increment), title, author, content
Insert String SQL = "insert into my_table values ('" + title + "', '" + author + "', '" + content + "')";
========================================================
Or you can use a sequence to achieve automatic growth:
Sequence
Create sequence my_id_seq
Increment by 1
Start with 1
Max value 999999999
NOCYCLE;
Use my_id_seq.nextval when adding
For example:
String SQL = "insert into my_table
Values (my_id_seq.nextval, '"+ title +"', '"+ author +"', '"+ content + "')";
Java method for automatic ID generation
Oracle:
Create sequence name
Create sequence XX_seq;
Auto-growth: XX_seq.nextval
MySql:
Add auto_increment after the primary key when creating the table. For example:
Create table student (
Id int (4) primary key auto_increment,
Name varchar (30) not null
);