隨筆心得

          記我所見,記我所想

          BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
            34 Posts :: 0 Stories :: 16 Comments :: 0 Trackbacks
          package com;

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

          public class Dbconnection {
              final static String DB_DRIVER = "com.microsoft.jdbc.sqlserver.SQLServerDriver";

              final static String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=information";

              final static String user = "sa";

              final static String password = "renxihai";

              Connection conn = null;

              Dbconnection() {
                  try {

                      Class.forName(DB_DRIVER).newInstance();
                      System.out.println("數(shù)據(jù)庫驅動程序注冊成功!");
                      conn = DriverManager.getConnection(url, user, password);
                      if (conn != null)
                          System.out.println("數(shù)據(jù)庫連接成功");

                  } catch (Exception e) {

                      e.printStackTrace();
                      System.out.println("數(shù)據(jù)庫連接失敗");

                  }
              }

              Connection getconn() {

                  return conn;

              }
              
              void cutConnection(Connection dbconn){
                  if (dbconn != null) {
                      try {
                          dbconn.close();
                          System.out.println("數(shù)據(jù)庫已經(jīng)關閉");
                      } catch (SQLException e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                      }
                  }
                     
                 
              }
             

          }
           
          posted on 2007-04-19 13:59 源自有緣 閱讀(205) 評論(0)  編輯  收藏

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 韶山市| 揭西县| 沧源| 郯城县| 武邑县| 修文县| 禄劝| 永和县| 蚌埠市| 远安县| 甘德县| 新建县| 聊城市| 德阳市| 青海省| 威宁| 孝义市| 台中市| 清水县| 巧家县| 连云港市| 平山县| 仁布县| 内黄县| 大名县| 丰城市| 博乐市| 南康市| 疏勒县| 平定县| 紫金县| 墨江| 徐州市| 浠水县| 商南县| 石河子市| 乾安县| 凉城县| 赣榆县| 建平县| 公主岭市|