import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class Test {
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/platform","root","admin");
PreparedStatement stmt = con.prepareStatement("");
stmt.setString(1, "");
stmt.executeUpdate();
PreparedStatement pStmt = con.prepareStatement("");
ResultSet result = pStmt.executeQuery();
if (result.next()) {
System.out.println(result.getInt(1));
}
// 应该上述操作都在try中, 并且添加finally关闭ResultSet PreparedStatement Connection
}
}
JDBC
最新推荐文章于 2025-08-09 18:20:04 发布