JAVA链接Mysql

 
  
import java.sql.*;

public class DBHelper {
    public static Connection getConnection() {
        Connection connection = null;
        String driver = "com.mysql.jdbc.Driver";
        // 数据库名test,mysql端口默认3306
        String url = "jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false";
        try {
            Class.forName(driver);
            // 用户名和密码分别是 root, 123456
            connection = DriverManager.getConnection(url, "root", "123456");
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return connection;
    }
}

 
 

你可能感兴趣的:(java,mysql,java,mysql)