package wf;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.jdbc.Statement;

public class driverManager {
    public static void main(String[] args) {
        Connection connection=null;
        Statement statement=null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
             connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123456");
//       String sql="insert into customers values(111,'王锋','1553728655','1994-9-26')";
//            String sql="delete from customers where id=123";
//            String sql="update customers set name='小小'"+"where id=123 " ;
             
             String sql="select id,name,birth,email from customers";
             
             
             statement=(Statement) connection.createStatement();
            ResultSet rs=statement.executeQuery(sql);
            while(rs.next()){
                int id=rs.getInt(1);//下标从1开始
                String name=rs.getString(2);
                String email=rs.getString(3);
                Date birth=rs.getDate(4);
                System.out.println(id);
                System.out.println(name);
                System.out.println(email);
                System.out.println(birth);
                
            }
           statement.execute(sql);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally{
            if(statement!=null){
                try {
                    statement.close();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }finally{
                    if(connection!=null){
                        try {
                            connection.close();
                        } catch (SQLException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }
                
            }
            }
    }
}