简体   繁体   中英

Execute T SQL in Spring JPA

I need to execute some T-SQL code in Java. I would be glad if it was possible in Spring. I have an ERP system, that is a little bit old, and some tasks we need to perform some T-SQL code, call a lot of procedures etc. The codes has about 200 lines. We want to automate it. Can I execute native SQL lines in Java. I mean just pass SQL statements that I execute in SQL Management Studio. I read about JdbcTestUtils, but it's deprecated. Isn't it any other solution for that?

Two thoughts come to mind. JdbcTemplates and Native Queries.

Spring provides an abstraction over JDBC called JdbcTemplates. With JdbcTemplates, you can execute any arbitrary SQL and organize the results into lists and objects. This is not really tied to JPA though.

Within JPA, you can use Native Queries. This is slightly more oriented to marshalling data back into Entities so if that what you are interested in, it might be a better choice. And you can execute named queries with the same EntityManager that JPA provides.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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