开发者

Send Multiple Data to DB in Spring

I have this scenario in my Spring MVC Apps.

User has to choose what hobbie开发者_如何转开发s he/she likes. He can choose at least one or many hobbies. My problem is this, If I need to save the list of hobbies into my DB, I am thinking of sending the list of hobbies that my user has chosen, delimited by a comma separator.

It's like this: Basketball, Singing, Dancing, Bowling

Now, In my stored procedure call in my DB called by JDBC DAO, I will just parse the List of string and then perform Insert Statements one by one?

I can use also the

Begin Try
 Begin Tran
  //perform series of inserts here
 Commit Tran
End Try
Begin Catch
 Rollback Tran
End Catch

I am thinking that this will limit the amount of transaction from my Spring JDBC to DB. This would guard me also from having incomplete transaction should the second or third insert fails.

I have heard about Spring Transaction Management feature but I really haven't had the chance to study it yet and I am sticking to what I know so far because of time constraints. Spring has so many modules and I do not have the time to study them all.

Do you think, given my current knowledge of Spring, my idea is OK?


The idea of managing your transactions inside a stored procedure is quite old-fashioned, but perfectly valid.

Spring provides JDBC and JTA transaction management, which helps with application-level transaction management. If you want to manage your transactions in the stored procedure instead, then you're not going to have much use for Spring's transaction stuff, so you can safely ignore it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜