package com.zr.connection;

import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import com.mysql.jdbc.Connection;
/**
 * 连接数据库工具类
 * @author 欧小峰
 *
 */
public class DBConnection {
	/**
	 * 
	 * @return 数据库连接对象
	 */
	 //1.数据库地址  (根据不同的数据标准是不一样)
	 // private  final  static String DBURL = "jdbc:mysql://localhost:3306/graduation_project?useUnicode=true&characterEncoding=UTF8";
	  //2.设置用户和密码
	  //private  final  static String  USERNAME = "root";
	 // private  final  static String  PASSWORD = "123";
		private  final  static String DBURL = "jdbc:mysql://172.18.23.54:3306/graduation_project?useUnicode=true&characterEncoding=UTF8";
	   private  final  static String  USERNAME = "root";
	   private  final  static String  PASSWORD = "123";
	  //3.设置驱动名称 (根据不同的数据标准是不一样)
	  private  final  static String  DBDRIVER = "com.mysql.jdbc.Driver";
	  /**
	   * 获取数据库连接
	   * @return  返回数据库连接
	   */
	  public  static  Connection  getConnection(){
		  Connection  con = null;
		  try {
			Class.forName(DBDRIVER);
			con  =  (Connection) DriverManager.getConnection(DBURL, USERNAME, PASSWORD);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		  return  con;
			
	  }
	  /**
	   * 关闭连接
	   * @param st Statement
	   * @param con Connection
	   * @throws SQLException
	   */
	  public static void  closeJDBC(Statement st,java.sql.Connection  con) throws SQLException{
		    if(st!=null){
		    	st.close();
		    }
		    if(con!=null){
		    	con.close();
		    }
		   
	  }
	public static void main(String[] args) {
		System.out.println(DBConnection.getConnection());
	}
}


@@ -266,298 +266,8 @@
 */%0D%0A
-%09 //1.%E6%95%B0%E6%8D%AE%E5%BA%93%E5%9C%B0%E5%9D%80  (%E6%A0%B9%E6%8D%AE%E4%B8%8D%E5%90%8C%E7%9A%84%E6%95%B0%E6%8D%AE%E6%A0%87%E5%87%86%E6%98%AF%E4%B8%8D%E4%B8%80%E6%A0%B7)%0D%0A%09 // private  final  static String DBURL = %22jdbc:mysql://localhost:3306/graduation_project?useUnicode=true&characterEncoding=UTF8%22;%0D%0A%09  //2.%E8%AE%BE%E7%BD%AE%E7%94%A8%E6%88%B7%E5%92%8C%E5%AF%86%E7%A0%81%0D%0A%09  //private  final  static String  USERNAME = %22root%22;%0D%0A%09 // private  final  static String  PASSWORD = %22123%22;%0D%0A
 %09%09pr
@@ -446,12 +446,14 @@
  = %22
-root
+qinhao
 %22;%0D%0A
@@ -502,16 +502,19 @@
 D = %22123
+456
 %22;%0D%0A%09  /

修改数据库1.1