If you accidentally use the keywords of the database, you will report the error “SQL error: 1064, sqlstate: 42000”
There are three solutions
1.Enclose the table name or field name in square brackets ([])
XML configuration:
<property name="desc" type="string" >
<column name="[DESC]" length="255" not-null="true" />
</property>
Note:
@Column(name = "[DESC]", nullable = false)
public String getDesc() { return this.desc; }
2. Enclose the table name or field name with two accents (‘). The accented key is the key to the left of the “1” key and the key to the top of the “tab” key on the keyboard. This symbol is also known as “inverted quotation marks.”
XML configuration:
<property name="desc" type="string" >
<column name="`DESC`" length="255" not-null="true" />
</property>
Note:
@Column(name = "`DESC`", nullable = false)
public String getDesc() { return this.desc; }
3. Use double quotation marks (“) to enclose the table name or field name
<property name="desc" type="string" >
<column name='"DESC"' length="255" not-null="true" />
</property>
Note:
@Column(name = "\"DESC\"", nullable = false)
public String getDesc() { return this.desc; }
Similar Posts:
- System.Data.SqlTypes.SqlNullValueException: ‘Data is Null. This method or property cannot be called on Null values.’
- [Solved] The length of the data truncation done by springboothinesdata for the column.
- Leet code 44 wildcard matching – wildcard matching – Java
- [Solved] SQL Error (3621): String or binary data would be truncated The statement has been terminated.
- [leetcode] 140. Word break II word split II
- [LeetCode] 291. Word Pattern II
- Treatment of MySQL database keyword as column name by mybatisplus — sqlsyntax errorexception: you have an error in your SQL syntax;
- [Solved] django DRF This field may not be null, This field cannot be blank
- Solution of data truncated for column ‘xxx’ in MySQL
- Android WebView monitors and rewrites window.history.go (- 1) method call