package 增删改查; import java.sql.*; public class Linkmysql { private static final String URL="jdbc:mysql://localhost:3306/test?&useSSL=false&serverTimezone=UTC"; private static final String Name="root"; private static final String Password="woshinidie668"; private static Connection conn=null; static { try { Class.forName("com.mysql.cj.jdbc.Driver"); System.out.println("加载驱动成功"); } catch(ClassNotFoundException e) { e.printStackTrace(); System.out.print("Error!"); } try { conn=DriverManager.getConnection(URL,Name,Password); } catch(Exception e) { e.printStackTrace(); System.out.println("数据库链接失败!"); } } public static Connection connection( ) { return conn; } public static void main(String[] args) throws SQLException { // TODO 自动生成的方法存根 Statement stmt=conn.createStatement( ); ResultSet rs=stmt.executeQuery("select name,password from user"); while(rs.next()) { System.out.println(rs.getString("name")+" "+rs.getString("password")); } } }