When should I turn off Java Preparedstatement?

In the "using prepared statements" tutorial, it states that they should always be closed Suppose I have a function

getPrice() {
}

I want to be called many times a second Should this method use each method call to open and close Preparedstatement? This seems to be a lot of expense

Solution

First, the Preparedstatement is never opened This is just a prepared statement to be executed The statement is sent to the RDBMS that executes the SQL statement compiled by Preparedstatement Connections to SQL statements should be opened during SQL queries and closed when no other RDMS calls are required

You can send many statements / preparedstatements as needed, provided that you terminate and close its resultset and Preparedstatement after completion, and then close the RDBMS connection

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>