1
2 Add the driver.
But not connected
later switched to version 8.0 drivers got only connection
3
4
在这里插入代码片
package newpackage;
/**
*
-
@author X
/
import java.io.;
import java.sql.*;
import com.mysql.jdbc.Connection;
public class JDBCTest {
public static void main(String[] args){// 第一步注册驱动
try{Class.forName(“com.mysql.jdbc.Driver”);
//step2 connect to the DB
String url=“jdbc:mysql://localhost:3000/web01?useUnicode=true&characterEncoding=UTF-8&useSSL=false”;
String userName=“root”;
String password=“root”;
java.sql.Connection con = DriverManager.getConnection(url,userName,password);
//step3 start Query
Statement stmt= con.createStatement();
ResultSet rs=stmt.executeQuery(“select * from user”);
while(rs.next()){
System.out.println(rs.getInt(1)+","+rs.getString(2)+","+rs.getString(3));}
if(rs!=null) rs.close();
if(stmt!=null) stmt.close();
if(con!=null) con.close();
}catch(Exception e){
e.printStackTrace();
}