mysql - java 中声明PreparedStatement类时出错(导入包:java.sql.*)
伊谢尔伦
伊谢尔伦 2017-04-17 13:35:41
0
3
840

java 中声明PreparedStatement类时出错(导入包:java.sql.*):The resource type PreparedStatement does not implement java.lang.AutoCloseable

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(3)
洪涛

The prototype of PreparedStatement is public interface PreparedStatement extends Statement, which is an interface. You need to implement all interfaces

Peter_Zhu

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.

迷茫

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template