Hi Guys! Can you advice some good method to reduc...
# server
p
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
Use Spring JdbcTemplate?
p
Maybe some tricky method to map response to data class?
f
I would use a mix of the above responses 🙂
m
Or MyBatis or JOOQ if you want something to manage the mappings more automatically.
m
• 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 🙂