【问题标题】:error when trying to insert varchar primary key into mysql through spring mvc app尝试通过spring mvc app将varchar主键插入mysql时出错
【发布时间】:2014-02-02 00:59:54
【问题描述】:

当我尝试从 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 时所需的语法有关,但我不确定。

【问题讨论】:

    标签: mysql sql spring spring-mvc


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢。 +1 试图提供帮助。你可能是对的。但是,当我添加以下单词 VALUES 后,我发现问题已得到解决: INSERT IGNORE INTO codes VALUES ('99503', 'Home visit for respiratory Therapy care');
    猜你喜欢
    • 1970-01-01
    • 2019-05-16
    • 1970-01-01
    • 2015-04-10
    • 1970-01-01
    • 2014-11-21
    • 1970-01-01
    • 2013-11-07
    • 1970-01-01
    相关资源
    最近更新 更多