java 中声明PreparedStatement类时出错(导入包:java.sql.*):The resource type PreparedStatement does not implement java.lang.AutoCloseable
PHP中文网2017-04-17 13:37:41
The prototype of PreparedStatement is public interface PreparedStatement extends Statement, which is an interface. You need to implement all interfaces
天蓬老师2017-04-17 13:37:41
You need to provide the code of the error line to confirm. Most likely you have a few lines of code like this:
try(
PreparedStatement pstmt = conn.prepareSatement("select ...");
){
...
}
Here you use the try-with-resource syntax added in recent versions of Java. This syntax requires that the variables defined within parentheses be the Closeable interface first. If the class library where PreparedSatement is used is older, it may not implement this interface.
Maybe the syntax you are using exceeds the version of the JRE library you reference.
迷茫2017-04-17 13:37:41
When I look at the error report, I see that the try with resources syntax of jdk7 is used. The resources in the try brackets must implement AutoCloseable, and PrepareStatement does not implement the AutoCloseable interface. Let’s use it differently, try-finally