swing学生管理系统Java源码案例

部分代码如下

package com.student.util;

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

public class DbUtil {
        private String dbUrl="jdbc:mysql://localhost:3306/db_student";
        private String user="root";
        private String password="123456";
        private String jdbcName="com.mysql.jdbc.Driver";
        public Connection getCon() throws Exception{
                Class.forName(jdbcName);
                Connection con=DriverManager.getConnection(dbUrl, user, password);
                return con;
        }
        public void close(Connection con)throws Exception{
                if(con!=null){
                        con.close();
                }
        }
        public static void main(String[] args){
                Connection con=null;
                try {
                        con = new DbUtil().getCon();
                        System.out.println(con);
                } catch (Exception e) {
                        e.printStackTrace();
                }finally{
                        if(con!=null){
                                try {
                                        con.close();
                                } catch (SQLException e) {
                                        e.printStackTrace();
                                }
                        }
                }
        }
}

  效果图
<ignore_js_op> 

<ignore_js_op> 

<ignore_js_op>

详细说明:http://java.662p.com/thread-3620-1-1.html

posted on 2014-11-21 09:13  baidulianweikjj  阅读(6799)  评论(1编辑  收藏  举报

导航