JDBC连接数据库(查询)
public class App { public static void main(String[] args) throws Exception { Class.forName( "com.mysql.cj.jdbc.Driver" ); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/vip?serverTimezone=GMT&useSSL=false", "root", "zhangpn" ); Statement stat = conn.createStatement(); ResultSet res = stat.executeQuery("select * from sys_user" ); while (res.next()){ System.out.println(res.getString( 1)+"***"+res.getString(2)+"***"+res.getString(3)+"***"+res.getString(4 )); } res.close(); stat.close(); conn.close(); } } 1.加载启动:Class.forName("com.mysql.cj.jdbc.Driver"); 2.获取连接