Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1473181
  • 博文数量: 108
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 997
  • 用 户 组: 普通用户
  • 注册时间: 2013-06-29 09:58
个人简介

兴趣是坚持一件事永不衰竭的动力

文章分类

全部博文(108)

文章存档

2021年(1)

2020年(10)

2019年(19)

2018年(9)

2016年(23)

2015年(43)

2013年(3)

我的朋友

分类: Java

2015-11-19 00:00:55

package com.ddChat.utils;


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


public class DbUtil
{
    
    public DbUtil()
    {
        super();
        // TODO Auto-generated constructor stub
    }
    private  String dbURL = "jdbc:mysql://localhost:3306/dd";
    private  String dbUserName = "root";
    private  String dbPassword = "fang";
    private  String jdbcName = "com.mysql.jdbc.Driver";
    public  Connection getCon() throws Exception
    {
        Class.forName(jdbcName);
        Connection con = DriverManager.getConnection(dbURL,dbUserName,dbPassword);
        return con;
    }
    public  void closeCon(Connection con) throws Exception
    {
        if(con != null)
        {
            con.close();
        }
    }
    public static void main(String[] args) {
        DbUtil dbUtil=new DbUtil();
        try {
            dbUtil.getCon();
            System.out.println("数据库连接成功");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }


}

阅读(1537) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~