Statement对象的executeUpdate方法用于向数据库发送增删改查的SQL语句,executeUpdate执行完成后,将会返回一个整数,即增删改语句导致了数据库几行数据发生了变化。
Statement对象的executeQuery方法用于向数据库发送查询语句,executeUpdate方法放回代表代表查询结果的ResultSet对象。
 driver = com.mysql.jdbc.Driver
 url = jdbc:mysql://localhost:3306/jdbcstudy?useUnicode=true&characterEncoding=utf8&useSSL=true
 username = root
 password = 123456
注意:每条语句结束后不能有“;”
 package utils;
 ?
 import java.io.IOException;
 import java.io.InputStream;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Properties;
 ?
 /**
  * 用于加载db.properties文件资源、加载驱动、获取连接、释放连接资源等
  */
 public class JdbcUtils {
     //属性信息
     private static String driver = null;
     private static String url = null;
     private static String username = null;
     private static String password = null;
 ?
     static {
         try{
             //加载资源
             InputStream in = JdbcUtils.class.getClassLoader().getResourceAsStream("db.properties");
 ?
             //获取资源
             Properties properties = new Properties();
             properties.load(in);
 ?
             //获取详细信息
             driver = properties.getProperty("driver");
             url = properties.getProperty("url");
             username = properties.getProperty("username");
             password = properties.getProperty("password");
 ?
             //1.驱动只用加载一次
             Class.forName(driver);
 ?
         } catch(IOException | ClassNotFoundException e){
             e.printStackTrace();
         } catch(Exception e){
             e.printStackTrace();
         }
     }
 ?
     /**
      * 获取连接
      * @return
      * @throws SQLException
      */
     public static Connection getConnection() throws SQLException {
         return DriverManager.getConnection(url,username,password);
     }
 ?
     /**
      * 释放连接资源
      * @param connection
      * @param statement
      * @param resultSet
      */
     public static void release(Connection connection, Statement statement, ResultSet resultSet){
         //关系的顺序依次为resultSet、statement、connection
         if(resultSet!=null){
             try {
                 resultSet.close();
             } catch (SQLException e) {
                 e.printStackTrace();
             } catch(Exception e){