import java.sql.*;
public class dome1 {
public static void main(String[] args) {
Connection connection=null;
Statement statement=null;
ResultSet resultSet=null;
try {
//1.链接到数据库
Class.forName("com.mysql.cj.jdbc.Driver");
//2.
String userName="root";
String passWord="123456";
String url="jdbc:mysql://localhost:3306/zuoye1?serverTimezone=UTC";
connection = DriverManager.getConnection(url, userName, passWord);
//3.定义sql,创建状态通道
statement = connection.createStatement();
resultSet = statement.executeQuery("select * from employee");
//4.取出结果集
while (resultSet.next()){
System.out.println("姓名:"+resultSet.getString("name"));
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException throwables) {
throwables.printStackTrace();
} finally {
try {
if (connection != null) {
connection.close();
}
if (statement != null) {
statement.close();
}
if (resultSet != null) {
resultSet.close();
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}
}