package jdbcdemo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class jdbcdemo {
private static final String url = "jdbc:mysql://127.0.0.1:3306/demo?useUnicode=true&characterEncoding=utf-8";
private static final String user = "root";
private static final String password = "doce";
public static void main(String[] args) throws Exception {
//1、加载mysql驱动
Class.forName("com.mysql.jdbc.Driver");
//2、获得数据库连接
Connection connection=DriverManager.getConnection(url ,user , password);
//3、通过连接操作数据库,实现增删改查
Statement statement=connection.createStatement();
//4、执行sql语句
ResultSet re = statement.executeQuery("select user_name,age from imooc_goddess;");
while(re.next()){
System.out.println(re.getString("user_name")+","+re.getInt("age"));
}
}}
AScorpio
相关分类