1个回答
展开全部
驱动
String driver = "com.mysql.jdbc.Driver";
// URL指向要访问的数据库名mydb
String url = "jdbc:mysql://127.0.0.1:3306/mydb";
// 用户名
String user = "root";
// Java连接MySQL密码
String password = "root";
try {
// 加载驱动
Class.forName(driver);
// 连续数据库
Connection conn = DriverManager.getConnection(url, user, password);
if(!conn.isClosed())
System.out.println("connecting to the Database Succee!");
// statement用来执行SQL语句
Statement statement = conn.createStatement();
// 要执行的SQL语句
String sql = "select * from student";
ResultSet rs=statement .executeQuery(sql);
while(rs.hasNext()){
//遍历取得结果
}
String driver = "com.mysql.jdbc.Driver";
// URL指向要访问的数据库名mydb
String url = "jdbc:mysql://127.0.0.1:3306/mydb";
// 用户名
String user = "root";
// Java连接MySQL密码
String password = "root";
try {
// 加载驱动
Class.forName(driver);
// 连续数据库
Connection conn = DriverManager.getConnection(url, user, password);
if(!conn.isClosed())
System.out.println("connecting to the Database Succee!");
// statement用来执行SQL语句
Statement statement = conn.createStatement();
// 要执行的SQL语句
String sql = "select * from student";
ResultSet rs=statement .executeQuery(sql);
while(rs.hasNext()){
//遍历取得结果
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询