package com;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
public class QuerTest {
public static void main(String[] args) throws Exception {
//连接数据库的url
String url = "jdbc:mysql://127.0.0.1:5653/wuzydb";
//数据库用户名
String user = "root";
//数据库密码
String password = "1111";
//1、加载驱动
Class.forName("com.mysql.jdbc.Driver");
//2、创建数据库连接对象
Connection conn = DriverManager.getConnection(url, user, password);
//3、创建Statement对象
Statement stmt = conn.createStatement();
//4、获取ResultSet
String sql = "select name,salary,age from t_emp";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
//获取字段name数据
String name = rs.getString("name");
//获取字段salary
double salary = rs.getDouble("salary");
//获取age数据
int age = rs.getInt("age");
System.out.println(name+ "," +salary+ "," +age);
}
//5、关闭数据库
rs.next();
stmt.close();
conn.close();
}
}