Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BLOOM-103] 식물 종류 검색 핫픽스 #104

Merged
merged 3 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading