-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from dnd-side-project/fix/plant-search
[BLOOM-103] 식물 종류 검색 핫픽스
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/main/kotlin/dnd11th/blooming/common/util/UpdatePlantDecomposedKorName.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters