CodeMed
CodeMed

Reputation: 9201

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

I am getting the following error message in the command line when I try to run my spring mvc app on tomcat server from within eclipse:

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

Note that the line of code that is throwing the error is:

INSERT IGNORE INTO codes('99503', 'Home visit for respiratory therapy care');

The code that creates the codes table is as follows:

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

How do I fix the code so that I can get past this error? My guess is that it has something to do with the syntax required when inserting a VARCHAR primary key into MySQL, but I am not certain.

Upvotes: 0

Views: 215

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270713

Try using the correct syntax. Here is one way:

INSERT IGNORE INTO cpt_codes
    select '99503', 'Home visit for respiratory therapy care';

You should actually specify the column names:

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

Upvotes: 1

Related Questions