This chapter provides an example of how to open a database connection, execute a SQL query, and display the results.
Requires that you include the packages containing the JDBC classes needed for database programming.
```Java
import java.sql.*;
/**
* Before executing an SQL statement with a Statement object, you need to create a Statement object using the createStatement() method of the Connection object.
* After creating a Statement object, you can use its execute() method to execute an SQL statement
* Finally, remember to close the 'statement' and 'connection' objects by using their close() method
* For statements with query results, we can use the getResultSet() method of the Statement object to get the result set.
*/
public static void main(String[] args) throws SQLException {
Before executing an SQL statement with a Statement object, you need to create a Statement object using the **createStatement()** method of the Connection object.
After creating a Statement object, you can use its **execute()** method to execute an SQL statement
Finally, remember to close the 'statement' and 'connection' objects by using their **close()** method
For statements with query results, we can use the **getResultSet()** method of the Statement object to get the result set.
```Java
public static void main(String[] args) throws SQLException {
/**
* Before executing an SQL statement with a Statement object, you need to create a Statement object using the createStatement() method of the Connection object.
* After creating a Statement object, you can use its execute() method to execute an SQL statement
* Finally, remember to close the 'statement' and 'connection' objects by using their close() method
* For statements with query results, we can use the getResultSet() method of the Statement object to get the result set.
*/
public static void main(String[] args) throws SQLException {
Connection connection = getConnection();
if (connection == null) {
System.out.println("get connection defeat");
...
...
@@ -109,42 +76,44 @@ For statements with query results, we can use the **getResultSet()** method of t