Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试通过SpringMVC应用程序将varchar主键插入mysql时出错_Mysql_Sql_Spring_Spring Mvc - Fatal编程技术网

尝试通过SpringMVC应用程序将varchar主键插入mysql时出错

尝试通过SpringMVC应用程序将varchar主键插入mysql时出错,mysql,sql,spring,spring-mvc,Mysql,Sql,Spring,Spring Mvc,当我尝试在eclipse中的tomcat服务器上运行spring mvc应用程序时,我在命令行中收到以下错误消息: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.jdbc.datasource.init.DataSourceInitializer#0': Invocation of init method failed;

当我尝试在eclipse中的tomcat服务器上运行spring mvc应用程序时,我在命令行中收到以下错误消息:

org.springframework.beans.factory.BeanCreationException:  
Error creating bean with name 'org.springframework.jdbc.datasource.init.DataSourceInitializer#0':
Invocation of init method failed; 
nested exception is org.springframework.dao.DataAccessResourceFailureException:  
Failed to execute database script;  
nested exception is org.springframework.jdbc.datasource.init.ScriptStatementFailedException: 
Failed to execute SQL script statement at line 68 of resource class path resource[db/mysql/populateDB.sql]: 
INSERT IGNORE INTO codes('99503', 'Home visit for respiratory therapy care')
请注意,引发错误的代码行是:

INSERT IGNORE INTO codes('99503', 'Home visit for respiratory therapy care');
创建代码表的代码如下所示:

CREATE TABLE IF NOT EXISTS codes(
  code VARCHAR(100) PRIMARY KEY,
  description VARCHAR(500)
)engine=InnoDB;

如何修复代码以克服此错误?我猜这与在MySQL中插入VARCHAR主键时所需的语法有关,但我不确定。

尝试使用正确的语法。这里有一个方法:

INSERT IGNORE INTO cpt_codes
    select '99503', 'Home visit for respiratory therapy care';
实际上,您应该指定列名:

INSERT IGNORE INTO cpt_codes(col1, col2)
    select '99503', 'Home visit for respiratory therapy care';

多谢各位+谢谢你的帮助。你可能是对的。然而,当我添加单词值时,我发现问题得到了解决,如下所示:在代码值中插入IGNORE('99503','呼吸治疗护理家访');