Hi Guys!
Can you advice some good method to reduce this spaghetti:
Copy code
val confirmAccountDeletionEmailStatement = configurationConnection().prepareStatement("SELECT t.id,t.name,t.subject,t.content FROM email_templates t WHERE name='confirm_account_deletion'")
val confirmAccountDeletionEmailResultSet = confirmAccountDeletionEmailStatement.executeQuery()
var confirmAccountDeletionEmailId = 0
var confirmAccountDeletionEmailName = ""
var confirmAccountDeletionEmailSubject = ""
var confirmAccountDeletionEmailContent = ""
while (confirmAccountDeletionEmailResultSet.next()) {
confirmAccountDeletionEmailId = confirmAccountDeletionEmailResultSet.getInt(1)
confirmAccountDeletionEmailName = confirmAccountDeletionEmailResultSet.getString(2)
confirmAccountDeletionEmailSubject = confirmAccountDeletionEmailResultSet.getString(3)
confirmAccountDeletionEmailContent = confirmAccountDeletionEmailResultSet.getString(4)
}
?
t
tddmonkey
07/27/2019, 11:37 AM
Use Spring JdbcTemplate?
p
pyrkamarcin
07/27/2019, 11:48 AM
Maybe some tricky method to map response to data class?
f
Felipe Assoline
07/27/2019, 12:15 PM
I would use a mix of the above responses 🙂
m
Mike
07/27/2019, 2:06 PM
Or MyBatis or JOOQ if you want something to manage the mappings more automatically.
m
Marc Knaup
07/27/2019, 3:15 PM
• Move the code into its own function so that you can get rid of the
confirmAccountDeletionEmail
variable name prefix.
• Show more code how the variables are used. You shouldn’t need
var
nor have a need for initializing the variable at all if there is no result in the result set. But for that more context is needed 🙂