(1)建立stu数据库;
(2)在数据库中建立student表,其结构为stuNum,stuName,age;
(3)在表中录入3条记录
(4)编程实现将Student表中所有记录读出,输出到控制台界面
import java.sql.*;
public class test {
public static void main(String[] args) throws Exception {
//Class.forName("com.mysql.cj.jdbc.Driver");可写可不写
String url="jdbc:mysql://localhost:3306/stu";
String user="root";
String pwd="123456";
Connection connection = DriverManager.getConnection(url,user,pwd);
Statement statement = connection.createStatement();
String sql="select * from student";
ResultSet resultSet = statement.executeQuery(sql);
while (resultSet.next()){
String stuNum = resultSet.getString("stuNum");
String stuName = resultSet.getString("stuName");
int age = resultSet.getInt("age");
System.out.println("学号:"+stuNum+"姓名;"+"年龄:"+stuName+age);
}
}
}