1、错误描述
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxError Exception:You have an error in your SQL syntax check the manual that corresponds to your MySQL server version for the right syntax to use near 'notnull,user_name
varchar(255) )' at line 1
2、错误原因
StringBuilder sql = new StringBuilder();
sql.append("create table t_you_su_ta(");
sql.append(" id int primary key,");
sql.append(" user_id int notnull,");
sql.append(" user_name varchar(255))");
在拼接创建数据库表时,要使user_id不为空,定义成了“notnull”
3、解决办法
在拼接user_id时,应改成“user_id int not null”
本文详细介绍了如何解决MySQL语法错误,其中指出在创建数据库表时,用户ID字段需要被正确地定义为非空(not null)。通过修改字符串拼接中的字段属性,可以避免此类错误并确保数据库表结构的正确性。
1117

被折叠的 条评论
为什么被折叠?



