Java面向对象编程+jdbc连接MySQL+日志Log4j 《项目搜搜移动大厅》

数据库连接类:DBHelp

package DBHelp;

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

public class DBHelp {
		 /**驱动程序名*/
		private static final   String driver = "com.mysql.jdbc.Driver";
		//访问数据库
		private static final String url = "jdbc:mysql://localhost:3306/food_db?"
		  		+ "useUnicode=true&characterEncoding=UTF8";//防止乱码出现
		  /**MySQL配置时的用户名*/
		private static final  String user = "root";
		   //MySQL配置时的密码
		private static final  String password = "443650890";
		//声明Connection对象
		private static Connection con = null;
		/**
		 * 连接数据库
		 * @return 返回Connection对象
		 * */
	 public static Connection mysqlConn() {
			   try {
				Class.forName(driver); //加载驱动程序
				 /**1.getConnection()方法,连接MySQL数据库!!*/
				   con = (Connection) DriverManager.getConnection(url,user,password);
			} catch (ClassNot

你可能感兴趣的:(mysql,eclipse,java,数据库,jdbc)