posts - 48,  comments - 5,  trackbacks - 0

          import java.sql.Connection;

          import java.sql.DriverManager;

          import java.sql.SQLException;

           

          /**

           *

           * @author 逍湘

           *

           */

          public class Java_Odbc_Sql {

              /**

               * drivename odbc驅動

               * url中的username為數據源名

               */

               private static final String drivename="sun.jdbc.odbc.JdbcOdbcDriver";

               private static final String url="jdbc:odbc:username;user=sa;password=123" ;

               /**

                * odbc連接數據庫方法: getCon()

                * @return con

                * @throws Exception

                */

               public  static void  getCon() throws Exception{

                     try {

                               Class.forName(drivename);//JVM中注冊JDBC驅動程序

                               @SuppressWarnings("unused")

                              Connection con=DriverManager.getConnection(url);//建立到DBMS的連接                   

                             } 

                     catch (SQLException e) {

                              System.err.println(e.getMessage());

                               throw e;

                     }

                     catch (Exception e) {

                         System.err.println(e.getMessage());

                          throw e;

                }

                    

                }

               /**

                * 連接測試

                * @param agrs

                */

                public static void main(String agrs[]){

                       try{

                          getCon();

                            System.out.println("連接成功!");         

                       }catch(Exception e){

                           System.out.println("連接失敗!");

                           e.printStackTrace();

                       }

                       

                    }

          }

          posted on 2008-01-05 10:32 逍湘 閱讀(1103) 評論(0)  編輯  收藏

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


          網站導航:
           

          留言簿(2)

          隨筆檔案(49)

          文章檔案(17)

          最新隨筆

          積分與排名

          • 積分 - 26486
          • 排名 - 1493

          最新評論

          閱讀排行榜

          主站蜘蛛池模板: 都安| 潼关县| 响水县| 玉门市| 紫阳县| 济阳县| 务川| 伊春市| 资兴市| 凤凰县| 大渡口区| 凤山县| 通江县| 太康县| 武隆县| 崇州市| 南岸区| 洛宁县| 阳泉市| 托里县| 贵定县| 博爱县| 凌源市| 新源县| 雷州市| 石楼县| 宁远县| 高碑店市| 勐海县| 穆棱市| 轮台县| 辽宁省| 涞源县| 灌云县| 阆中市| 峨眉山市| 石渠县| 秦安县| 杭锦后旗| 保德县| 常熟市|