Skip to content

Commit

Permalink
Merge pull request #104 from dnd-side-project/fix/plant-search
Browse files Browse the repository at this point in the history
[BLOOM-103] 식물 종류 검색 핫픽스
  • Loading branch information
Dompoo authored Sep 7, 2024
2 parents cb00e3c + 5599378 commit ec4ada5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package dnd11th.blooming.common.util

import java.sql.Connection
import java.sql.DriverManager
import java.sql.PreparedStatement

fun decomposeKorName() {
val url = System.getenv("DB_URL")
val username = System.getenv("DB_USERNAME")
val password = System.getenv("DB_PASSWORD")

var connection: Connection? = null
var selectStatement: PreparedStatement? = null
var updateStatement: PreparedStatement? = null

try {
connection = DriverManager.getConnection(url, username, password)

val selectQuery = "SELECT id, kor_name FROM plant"
selectStatement = connection.prepareStatement(selectQuery)

val updateQuery = "UPDATE plant SET decomposed_kor_name = ? WHERE id = ?"
updateStatement = connection.prepareStatement(updateQuery)

val resultSet = selectStatement.executeQuery()

while (resultSet.next()) {
val id = resultSet.getInt("id")
val korName = resultSet.getString("kor_name")

val decomposedHangul = korName.toDecomposedHangul()

updateStatement.setString(1, decomposedHangul)
updateStatement.setInt(2, id)
updateStatement.executeUpdate()
}
} catch (e: Exception) {
e.printStackTrace()
} finally {
updateStatement?.close()
selectStatement?.close()
connection?.close()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Plant(
@Column
var pests: String,
@Column
@Enumerated(EnumType.STRING)
var location: GrowLocation,
@Column
var imageUrl: String,
Expand Down

0 comments on commit ec4ada5

Please sign in to comment.