import java.sql.*;
public class JDBC {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
//1.注册驱动
Class.forName("com.mysql.cj.jdbc.Driver");
//2.获取连接
String url="jdbc:mysql://localhost:3306/db_school";
String uername="root";
String password="123456";
Connection connection = DriverManager.getConnection(url,uername,password);
//3.定义sql语句
String sql = "SELECT * FROM sc";
//4.获取执行sql的对象Statement
Statement statement = connection.createStatement();
//5.执行sql
ResultSet count=statement.executeQuery(sql);
//受影响的行数
//6.处理结果
System.out.println(count);
//7.释放资源
statement.close();
connection.close();
}
}
06-26
1652
