繁体   English   中英

尝试通过spring mvc app将varchar主键插入mysql时出错

[英]error when trying to insert varchar primary key into mysql through spring mvc app

当我尝试从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;

如何修复代码,以便克服该错误? 我的猜测是,它与将VARCHAR主键插入MySQL时所需的语法有关,但我不确定。

尝试使用正确的语法。 这是一种方法:

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';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM