隨筆-20  評論-3  文章-9  trackbacks-0

          package com.mao.dbc;

          import java.sql.*;

          public class DataBaseConnection {
          ?final String dbdriver = "com.mysql.jdbc.Driver";
          ?final String dburl = "jdbc:mysql://localhost:3306/test";
          ?final String dbuser = "root";
          ?final String dbpass = "3100949";

          ?Connection conn = null;

          ?public DataBaseConnection() {
          ??try {
          ???Class.forName(dbdriver);
          ???conn = DriverManager.getConnection(dburl, dbuser, dbpass);
          ??} catch (Exception e) {
          ???// TODO Auto-generated catch block
          ???e.printStackTrace();
          ???System.out.println("數據庫連接出錯");
          ??}
          ?}

          ?public Connection getConnection() {
          ??return this.conn;
          ?}

          ?public void close() {
          ??try {
          ???this.conn.close();
          ??} catch (SQLException e) {
          ???// TODO Auto-generated catch block
          ???System.out.println("關閉連接");
          ??}
          ?}
          }

          posted on 2008-06-04 14:54 藍山 閱讀(145) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 东海县| 舒兰市| 舟曲县| 华阴市| 措勤县| 北辰区| 永昌县| 婺源县| 红桥区| 周宁县| 会宁县| 霍邱县| 古丈县| 贵南县| 廊坊市| 嘉祥县| 城口县| 望奎县| 扶余县| 永新县| 淄博市| 八宿县| 易门县| 深圳市| 邵东县| 吉林市| 武定县| 喀喇沁旗| SHOW| 绥德县| 商河县| 织金县| 分宜县| 通辽市| 兴业县| 浮山县| 宣城市| 息烽县| 金秀| 巴林左旗| 莱西市|