| | |
Function Introduction
- Supports converting SQL table creation statements to Java for various databases, including PostgreSQL, Oracle, and MySQL; table creation statements, table creation statements, table creation statements (emphasized thrice for importance).
- When converting SQL, you need to confirm whether to switch processing types, currently supporting three modes (normal, postgresql, oracle), default: normal.
- Supports customization for the need of
lombok
,package name
, andcamel case
.
Note: Comments cannot be included in SQL (i.e.,-- xxx
or# xxx
); this tool processes statements separated by ;. Therefore, in normal mode, multiple table creation statements can be handled simultaneously, while postgresql and oracle only support single statements due to the need to parse comments.
Examples
MySQL Table Creation Statement
CREATE TABLE if not exists user (
id int NOT NULL AUTO_INCREMENT,
name varchar(10) NOT NULL COMMENT 'Name',
gender tinyint NOT NULL DEFAULT 0 COMMENT 'Gender 0-unknown 1-male 2-female',
age int NOT NULL COMMENT 'Age',
created_date datetime DEFAULT CURRENT_TIMESTAMP,
updated_date datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id)
);
After treatment
// Code generated by https://gotool.top
package com.gotool.sql2java;
public class User {
private Integer id;
/**
* Name
*/
private String name;
/**
* Gender 0-unknown 1-male 2-female
*/
private Integer gender;
/**
* Age
*/
private Integer age;
private Date created_date;
private Date updated_date;
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public Integer getGender() {
return this.gender;
}
public void setGender(Integer gender) {
this.gender = gender;
}
public Integer getAge() {
return this.age;
}
public void setAge(Integer age) {
this.age = age;
}
public Date getCreated_date() {
return this.created_date;
}
public void setCreated_date(Date created_date) {
this.created_date = created_date;
}
public Date getUpdated_date() {
return this.updated_date;
}
public void setUpdated_date(Date updated_date) {
this.updated_date = updated_date;
}
}
pgsql table construction clause
CREATE TABLE if not exists user (
id character varying(32) NOT NULL DEFAULT sys_guid(),
name character varying(10) NOT NULL,
gender tinyint NOT NULL,
age tinyint NOT NULL,
created_date timestamp without time zone DEFAULT now(),
updated_date timestamp without time zone DEFAULT now(),
CONSTRAINT user_pkey PRIMARY KEY (id)
);
COMMENT ON TABLE user IS 'User table';
COMMENT ON COLUMN user.id IS 'Primary key';
COMMENT ON COLUMN user.name IS 'Name';
COMMENT ON COLUMN user.gender IS 'Gender 0-unknown 1-male 2-female';
COMMENT ON COLUMN user.age IS 'Age';
COMMENT ON COLUMN user.created_date IS 'Creation time';
COMMENT ON COLUMN user.updated_date IS 'Update time';
After treatment
// Code generated by https://gotool.top
package com.gotool.sql2java;
public class User {
/**
* Primary key
*/
private String id;
/**
* Name
*/
private String name;
/**
* Gender 0-unknown 1-male 2-female
*/
private Integer gender;
/**
* Age
*/
private Integer age;
/**
* Creation time
*/
private Integer createdDate;
/**
* Update time
*/
private Integer updatedDate;
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public Integer getGender() {
return this.gender;
}
public void setGender(Integer gender) {
this.gender = gender;
}
public Integer getAge() {
return this.age;
}
public void setAge(Integer age) {
this.age = age;
}
public Date getCreated_date() {
return this.created_date;
}
public void setCreated_date(Date created_date) {
this.created_date = created_date;
}
public Date getUpdated_date() {
return this.updated_date;
}
public void setUpdated_date(Date updated_date) {
this.updated_date = updated_date;
}
}
oracle build statement
CREATE TABLE if not exists user (
id character varying(32) NOT NULL DEFAULT sys_guid(),
name character varying(10) NOT NULL,
gender tinyint NOT NULL,
age tinyint NOT NULL,
created_date date default sysdate,
updated_date date default sysdate,
CONSTRAINT user_pkey PRIMARY KEY (id)
);
COMMENT ON TABLE user IS 'User table';
COMMENT ON COLUMN user.id IS 'Primary key';
COMMENT ON COLUMN user.name IS 'Name';
COMMENT ON COLUMN user.gender IS 'Gender 0-unknown 1-male 2-female';
COMMENT ON COLUMN user.age IS 'Age';
COMMENT ON COLUMN user.created_date IS 'Creation time';
COMMENT ON COLUMN user.updated_date IS 'Update time';
After treatment
// Code generated by https://gotool.top
package com.gotool.sql2java;
public class User {
/**
* Primary key
*/
private String id;
/**
* Name
*/
private String name;
/**
* Gender 0-unknown 1-male 2-female
*/
private Integer gender;
/**
* Age
*/
private Integer age;
/**
* Creation time
*/
private Integer createdDate;
/**
* Update time
*/
private Integer updatedDate;
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public Integer getGender() {
return this.gender;
}
public void setGender(Integer gender) {
this.gender = gender;
}
public Integer getAge() {
return this.age;
}
public void setAge(Integer age) {
this.age = age;
}
public Date getCreated_date() {
return this.created_date;
}
public void setCreated_date(Date created_date) {
this.created_date = created_date;
}
public Date getUpdated_date() {
return this.updated_date;
}
public void setUpdated_date(Date updated_date) {
this.updated_date = updated_date;
}
}