package com.gylhaut.db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class DBUtil {
//databaseweb数据库名称
private static final String URL="jdbc:mysql://localhost:3306/databaseweb";
private static final String NAME="root";
private static final String PASSWORD="123456";
public static void main(String[] args) throws Exception{
//1.加载驱动程序
Class.forName("com.mysql.jdbc.Driver");
//DriverManager.registerDriver(new com.mysql.jdbc.Driver());
//2.获得数据库的连接
Connection conn= DriverManager.getConnection(URL,NAME,PASSWORD);
//2.获得数据库的连接
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.getInt("age"));
}
}
}