我遇到了一個簡單的問題,但我不知道爲什麼。 第一個SQL可以創建表,第二個不能。爲什麼?無法使用Java在MySQL中創建表格
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)
我只是想設置表的引擎......
最終你得到什麼錯誤? –
你在使用什麼數據庫(MySQL,Oracle,SQL Server等)? –
@MarkMadej mysql –