package com.imooc.dbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class DBUtil { private static final String URL="jdbc:mysql://127.0.0.1:3306/imooc"; private static final String USER="root"; private static final String PASSWORD="toor"; public static void main(String[] args)throws Exception { //1.加载驱动程序 Class.forName("com.mysql.jdbc.Diver"); //2.获得数据库的连接 Connection conn=DriverManager.getConnection(URL, USER, PASSWORD); //3.通过数据库的连接操纵数据库,实现增删查改 Statement stmt = conn.createStatement(); ResultSet rs=stmt.executeQuery("select user_name,age from imooc_goddess"); while(rs.next()){ System.out.println(rs.getString("user_name")+","+rs.getString("age")); } } }
qq_昼绽_0
相关分类