当前位置:Gxlcms > 数据库问题 > java 连接 mysql

java 连接 mysql

时间:2021-07-01 10:21:17 帮助过:22人阅读

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnection {

	private static final String name = "root";
	private static final String pass = "";

	public static Connection ConnectDB() {
		Connection con = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/mytestdb", name, pass);

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return con;
	}
}


java 连接 mysql

标签:java mysql

人气教程排行