我遇到了一个简单的问题,但我不知道为什么。 第一个SQL可以创建表,第二个可以创建表。为什么呢?
String temString = "create table if not exists test(number int not null, name varchar(20) not null, primary key(number))engine=myisam default charset=utf8";
String createTableString = "create table if not exists ju_users (ju_userID int not null, TaobaoID int not null, ju_userName varchar(20) not null, ju_userPWD varchar(10) not null, primary key (ju_userID)) engine=myisam defalut charset=utf8";
消息是:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'defalut charset=utf8' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
at com.mysql.jdbc.Util.getInstance(Util.java:360)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:978)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2530)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1907)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2141)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2077)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2062)
at mysql_test.Main.CreateTable(Main.java:132)
at mysql_test.Main.main(Main.java:159)
我只想设置表格的引擎......
答案 0 :(得分:5)
你拼写错误。
而不是:
defalut charset=utf8"
您的查询应以
结尾default charset=utf8"
答案 1 :(得分:0)
也许是因为"测试"之后没有空间。 (你的第二个表名)?
我实际上对第一部作品感到惊讶,因为你拼写错误"默认"太
尝试粗体每个中的文字使其变得非常明显,但大胆的不在块引用或代码示例中工作,抱歉!