【发布时间】:2021-06-25 11:51:54
【问题描述】:
try (Connection connection = DriverManager
.getConnection("jdbc:mysql://localhost:3306/mysql_database?useSSL=false", "root", "root");
// Step 2:Create a statement using connection object
PreparedStatement preparedStatement = connection.prepareStatement(UPDATE_USERS_SQL)) {
preparedStatement.setString(1, "Ram");
preparedStatement.setInt(2, 1);
// Step 3: Execute the query or update query
preparedStatement.executeUpdate();
为每个查询创建连接对象并关闭它很昂贵,有没有其他方法可以在 spring boot 中使用准备好的语句,其次如何创建连接对象,我在 application.yml 文件中有数据库信息
【问题讨论】:
-
您可以为此使用 spring JDBC API。 spring.io/guides/gs/relational-data-access
标签: spring-boot