import java.sql.*;
public class TestMySQL {
public TestMySQL() {
}
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","root");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from student");
while(rs.next()){
System.out.println(rs.getString(2));
}
stmt.close();
conn.close();
}
catch (SQLException ex) {
ex.printStackTrace();
}catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
}
}
解释一下下面这句话
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","root");
mysql--数据库名
两个root,前面一个是用户名,后面一个是密码