错误如下:
java.sql.SQLException: 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 '2011-02-09bf(hljid int not null auto_increment,biao_name varchar(30),dengtime1 v' at line 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2921)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2972)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
at com.mysql.jdbc.Statement.executeUpdate(Statement.java:929)
at com.petroleum.jdbc.create_table.create(create_table.java:36)
at com.petroleum.jdbc.create_table.main(create_table.java:49)
java.sql.SQLException: 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 '2011-02-09bf(hljid int not null auto_increment,biao_name varchar(30),dengtime1 v' at line 1我想用JAVA在后台JDBC下直接建立一个新的数据库,语句写好了运行出现这个错误,找高手帮忙解决下!所用数据库MYsql

解决方案 »

  1.   

    String sql="create table "+time1+"bf(hljid int not null auto_increment,biao_name varchar(30),dengtime1 varchar(30),dengtime2 varchar(30),redundancy1 varchar(50),redundancy2 varchar(50),redundancy3 varchar(50),redundancy4 varchar(100),redundancy5 varchar(100),primary key(hljid))type=InnoDB;";
    System.out.println("sql======"+sql);这个是要执行的SQL语句
      

  2.   

    time1的值为2011-02-09,所以你的表名为2011-02-09bf,不是有效的名字
    '-' 作为表的名字是非法的
      

  3.   

    在开发中 编写sql语句的时候 你可以将动态生成的sql代码输出 在复制到数据库中尝试一下啊!
      

  4.   

    你在拼SQL字符串的时候没有注意空格
      

  5.   

    极有可能是sql语句有问题,你将写好的sql语句现在客户端运行一下看能否执行成功,在放到程序中