java操作JDBC之MySQL工具类

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Rodge_Rom/article/details/82938141
/**
* JDBC之MySQL工具类
*
* @author:  Rodge
* @time:    2018年10月4日 下午4:03:42
* @version: V1.0.0
*/
public class JDBCUtilForMySQL {
	
	private static final String URL = "jdbc:mysql://localhost:3306/test";
	private static final String USER = "root";
	private static final String PASSWORD = "1234";
	private static Connection conn = null;
	
	static {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection(URL, USER, PASSWORD);
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}
	
	/**
	 * 获取数据库连接
	 * @return
	 */
	public static Connection getConnection () {
		return conn;
	}
	
	public static void main(String[] args) {
		System.out.println(JDBCUtilForMySQL.getConnection());
	}
}

猜你喜欢

转载自blog.csdn.net/Rodge_Rom/article/details/82938141