Run script with EntityManager JPA on Mysql

后端 未结 1 319
北海茫月
北海茫月 2021-01-16 21:19

I\'m trying to run a script (.sql file) but i have multiples errors since i tried many ways, here\'s my main sql script:

INSERT INTO `Unity` VALUES (11,\'paq         


        
相关标签:
1条回答
  • 2021-01-16 22:00

    You can't execute the script by the em.createNativeQuery, as i know. You should to split the script into statements and execute them one by one.

    You may use ScriptRunner. It can be used separately from the MyBatis.

    Example:

    em.getTransaction().begin();
    Connection connection = em.unwrap(Connection.class);
    ScriptRunner sr = new ScriptRunner(connection);
    sr.runScript(new StringReader("INSERT INTO `Unity` VALUES (11,'paq',0,'2013-04-15 11:41:37','Admin','Paquete','Paq',0,'2013-04-15 11:41:37','AAA010101AAA',NULL);\r\nINSERT INTO `product` VALUES (11,'chi','USD','chi one',0,'2013-04-15 11:42:13',0,'Admin','Chi name',0.25,0,15,'2013-04-15 11:42:13','AAA010101AAA',NULL);"));
    em.getTransaction().commit();
    
    0 讨论(0)
提交回复
热议问题