JDBC connection database

package com.li.test;
Import java.sql.*;
Public class JDBCExample {
    Static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    Static final String JDBC_URL = "jdbc:mysql://localhost/test?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false";
    Static final String USER = "root";
    Static final String PASS = "root";
    Public static void main(String[] args) {
        Connection conn = null;
        Statement stmt = null;
        Try {
            //Get the driver
            Class.forName(JDBC_DRIVER);
            //Get the connection
            Conn = DriverManager.getConnection(JDBC_URL, USER, PASS);
            / / Create an execution object
            Stmt = conn.createStatement();
            String sql;
            Sql = "SELECT * FROM employees";
            / / Execute SQL, processing results
            ResultSet rs = stmt.executeQuery(sql);
            While (rs.next()) {
                String EMPLOYEES_NUM = rs.getString("EMPLOYEES_NUM");
                System.out.println("EMPLOYEES_NUM:" + EMPLOYEES_NUM);
            }
            / / Close the resource
            Rs.close();
            Stmt.close();
            Conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Try {
                If (stmt != null) {
                    Stmt.close();
                }
                If (conn != null) {
                    Conn.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
}

The most basic five steps, the interview is enough:

1. Get the connection driver

2. Create the database connection

3. Create the execution object

4. SQL, processing results

5. Close the resource

You can create a table, test it yourself, the code is tested without problems! ! !