<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 188,comments - 176,trackbacks - 0

    一、四種驅(qū)動程序概念

     

    A、JDBC-ODBC Bridge


        橋接器型的驅(qū)動程序,這類驅(qū)動程序的特色是必須在使用者端的計算機上事先安裝好ODBC驅(qū)動程序,然后通過JDBC-ODBC的調(diào)用方法,進(jìn)而通過ODBC來存取數(shù)據(jù)庫。


        作為JDK1.1后的一部分,是sun.jdbc.odbc包的一部分 Application--->JDBC-ODBC  Bridge---->JDBC-ODBC  Library--->ODBC  Driver-->Database 適用于快速的原型系統(tǒng),沒有提供JDBC驅(qū)動的數(shù)據(jù)庫如Access

     

    B、JDBC-Native API Bridge 


        也是橋接器驅(qū)動程序之一,這類驅(qū)動程序也必須先在使用者計算機上先安裝好特定的驅(qū)動程序(類似ODBC),然后通過JDBC-Native API橋接器的轉(zhuǎn)換,把Java API調(diào)用轉(zhuǎn)換成特定驅(qū)動程序的調(diào)用方法,進(jìn)而存取數(shù)據(jù)庫。


        利用開發(fā)商提供的本地庫來直接與數(shù)據(jù)庫通信。 Application--->JDBC  Driver---->Native  Database  library---->Database 比A類性能略好。

     

    C、JDBC-middleware


        這類型的驅(qū)動程序最大的好處就是省去了在使用者計算機上安裝任何驅(qū)動程序的麻煩,只需在服務(wù)器端安裝好middleware,而middleware會負(fù)責(zé)所有存取數(shù)據(jù)庫必要的轉(zhuǎn)換。Application--->Jdbc  Driver----->java  middleware--->JDBC  Driver---->Database 具有最大的靈活性,通常由那些非數(shù)據(jù)庫廠商提供,是四種類型中最小的。

     

    D、Pure JDBC driver


        這類型的驅(qū)動程序是最成熟的JDBC驅(qū)動程序,不但無需在使用者計算機上安裝任何額外的驅(qū)動程序,也不需要在服務(wù)器端安裝任何中介程序(middleware),所有存取數(shù)據(jù)庫的操作,都直接由驅(qū)動程序來完成。


        Application--->Jdbc  driver----->database  engine--->database 最高的性能,通過自己的本地協(xié)議直接與數(shù)據(jù)庫引擎通信,具備在Internet裝配的能力。

     


    二、常用的JDBC類與方法

     

    1、DriverManager類:


        負(fù)責(zé)管理JDBC驅(qū)動程序。使用JDBC驅(qū)動程序之前,必須先將驅(qū)動程序加載并向DriverManager注冊后才可以使用,同時提供方法來建立與數(shù)據(jù)庫的連接。

    方法:
    A、Class.forName(String driver); //加載注冊驅(qū)動程序


    B、Static Connection getConnection(String url,String user,String password) throws SQLException;  


            //取得對數(shù)據(jù)庫的連接
    C、Static Driver getDriver(String url) throws SQLExcetion;
            //在已經(jīng)向DriverManager注冊的驅(qū)動程序中尋找一個能夠打開url所指定的數(shù)據(jù)庫的驅(qū)動程序


    2、Connection類 


        負(fù)責(zé)維護(hù)JSP/JAVA數(shù)據(jù)庫程序和數(shù)據(jù)庫之間的聯(lián)機。可以建立三個非常有用的類對象。

    方法:
    A、Statement createStatement() throws SQLException; //建立Statement類對象
       Statement createStatement(int resultSetType,int resultSetConcurrency) throws SQLException;   
       // 建立Statement類對象

    resultSetType值 
    TYPE_FORWARD_ONLY 結(jié)果集不可滾動 
    TYPE_SCROLL_INSENSITIVE 結(jié)果集可滾動,不反映數(shù)據(jù)庫的變化 
    TYPE_SCROLL_SENSITIVE 結(jié)果集可滾動,反映數(shù)據(jù)庫的變化 

    resultSetConcurrency值 
    CONCUR_READ_ONLY 不能用結(jié)果集更新數(shù)據(jù) 
    CONCUR_UPDATABLE 能用結(jié)果集更新數(shù)據(jù) 

    JDBC2.0中才支持滾動的結(jié)果集,而且可以對數(shù)據(jù)進(jìn)行更新

    B、DatabaseData getData() throws SQLException; //建立DatabaseData類對象


    C、PreparedStatement prepareStatement(String sql) throws SQLException; 
            //建立PreparedStatement類對象


    D、boolean getAutoCommit() throws SQLException //返回Connection類對象的AutoCommit

    狀態(tài)
    E、void setAutoCommit(boolean autoCommit) throws SQLException 
            //設(shè)定Connection類對象的AutoCommit狀態(tài)


    F、void commit() throws SQLException  //確定執(zhí)行對數(shù)據(jù)庫新增、刪除或修改記錄的操作


    G、void rollback() throws SQLException  //取消執(zhí)行對數(shù)據(jù)庫新增、刪除或修改記錄的操作


    H、void close() throws SQLException  //結(jié)束Connection對象對數(shù)據(jù)庫的聯(lián)機


    I、boolean isClosed() throws SQLException //測試是否已經(jīng)關(guān)閉Connection類對象對數(shù)據(jù)庫的聯(lián)機

     

    3、Statement類

     

        通過Statement類所提供的方法,可以利用標(biāo)準(zhǔn)的SQL命令,對數(shù)據(jù)庫直接新增、刪除或修改操作

    方法:

     A、ResultSet executeQuery(String sql) throws SQLException //使用SELECT命令對數(shù)據(jù)庫進(jìn)行查詢


    B、int executeUpdate(String sql) throws SQLException 
            //使用INSERT\DELETE\UPDATE對數(shù)據(jù)庫進(jìn)行新增、刪除和修改操作。


    C、void close() throws SQLException //結(jié)束Statement類對象對數(shù)據(jù)庫的聯(lián)機


    4、PreparedStatement類

        PreparedStatement類和Statement類的不同之處在于PreparedStatement類對象會將傳入的SQL命令事先編好等待使用,當(dāng)有單一的SQL指令比多次執(zhí)行時,用PreparedStatement類會比Statement類有效率

    方法:

    A、ResultSet executeQuery() throws SQLException //使用SELECT命令對數(shù)據(jù)庫進(jìn)行查詢


    B、int executeUpdate() throws SQLException 
            //使用INSERT\DELETE\UPDATE對數(shù)據(jù)庫進(jìn)行新增、刪除和修改操作。


    C、ResultSetData getData() throws SQLException
            //取得ResultSet類對象有關(guān)字段的相關(guān)信息


    D、void setInt(int parameterIndex,int x) throws SQLException
            //設(shè)定整數(shù)類型數(shù)值給PreparedStatement類對象的IN參數(shù)


    E、void setFloat(int parameterIndex,float x) throws SQLException
            //設(shè)定浮點數(shù)類型數(shù)值給PreparedStatement類對象的IN參數(shù)


    F、void setNull(int parameterIndex,int sqlType) throws SQLException
            //設(shè)定NULL類型數(shù)值給PreparedStatement類對象的IN參數(shù)


    G、void setString(int parameterIndex,String x) throws SQLException
            //設(shè)定字符串類型數(shù)值給PreparedStatement類對象的IN參數(shù)


    H、void setDate(int parameterIndex,Date x) throws SQLException
            //設(shè)定日期類型數(shù)值給PreparedStatement類對象的IN參數(shù)


    I、void setTime(int parameterIndex,Time x) throws SQLException
            //設(shè)定時間類型數(shù)值給PreparedStatement類對象的IN參數(shù)

     

    5、DatabaseData類

        DatabaseData類保存了數(shù)據(jù)庫的所有特性,并且提供許多方法來取得這些信息。

    方法:

    A、String getDatabaseProductName() throws SQLException //取得數(shù)據(jù)庫名稱


    B、String getDatabaseProductVersion() throws SQLException //取得數(shù)據(jù)庫版本代號


    C、String getDriverName() throws SQLException //取得JDBC驅(qū)動程序的名稱


    D、String getDriverVersion()  throws SQLException //取得JDBC驅(qū)動程序的版本代號


    E、String getURL() throws SQLException //取得連接數(shù)據(jù)庫的JDBC URL


    F、String getUserName() throws SQLException //取得登錄數(shù)據(jù)庫的使用者帳號

     

    6、ResultSet類

        負(fù)責(zé)存儲查詢數(shù)據(jù)庫的結(jié)果。并提供一系列的方法對數(shù)據(jù)庫進(jìn)行新增、刪除和修改操作。也負(fù)責(zé)維護(hù)一個記錄指針(Cursor),記錄指針指向數(shù)據(jù)表中的某個記錄,通過適當(dāng)?shù)囊苿佑涗浿羔槪梢噪S心所欲的存取數(shù)據(jù)庫,加強程序的效率。

    方法:

    A、boolean absolute(int row) throws SQLException  //移動記錄指針到指定的記錄


    B、void beforeFirst() throws SQLException  //移動記錄指針到第一筆記錄之前


    C、void afterLast() throws SQLException  //移動記錄指針到最后一筆記錄之后


    D、boolean first() throws SQLException  //移動記錄指針到第一筆記錄


    E、boolean last() throws SQLException  //移動記錄指針到最后一筆記錄


    F、boolean next() throws SQLException  //移動記錄指針到下一筆記錄


    G、boolean previous() throws SQLException  //移動記錄指針到上一筆記錄


    H、void deleteRow() throws SQLException  //刪除記錄指針指向的記錄


    I、void moveToInsertRow() throws SQLException  //移動記錄指針以新增一筆記錄


    J、void moveToCurrentRow() throws SQLException  //移動記錄指針到被記憶的記錄


    K、void insertRow() throws SQLException  //新增一筆記錄到數(shù)據(jù)庫中


    L、void updateRow() throws SQLException  //修改數(shù)據(jù)庫中的一筆記錄


    M、void update類型(int columnIndex,類型 x) throws SQLException  //修改指定字段的值


    N、int get類型(int columnIndex) throws SQLException  //取得指定字段的值


    O、ResultSetData getData() throws SQLException //取得ResultSetData類對象

     

    7、ResultSetData類

        ResultSetData類對象保存了所有ResultSet類對象中關(guān)于字段的信息,提供許多方法來取得這些信息。

    方法:

    A、int getColumnCount() throws SQLException //取得ResultSet類對象的字段個數(shù)


    B、int getColumnDisplaySize() throws SQLException //取得ResultSet類對象的字段長度


    C、String getColumnName(int column) throws SQLException //取得ResultSet類對象的字段名稱


    D、String getColumnTypeName(int column) throws SQLException //取得ResultSet類對象的字段類型名稱


    E、String getTableName(int column) throws SQLException //取得ResultSet類對象的字段所屬數(shù)據(jù)表的名稱


    F、boolean isCaseSensitive(int column) throws SQLException //測試ResultSet類對象的字段是否區(qū)分大小寫


    G、boolean isReadOnly(int column) throws SQLException //測試ResultSet類對象的字段是否為只讀

    posted on 2007-05-24 11:41 cheng 閱讀(1566) 評論(0)  編輯  收藏 所屬分類: SQLServer
    主站蜘蛛池模板: 亚洲精品免费观看| 狠狠入ady亚洲精品| 色妞WWW精品免费视频| 亚洲熟妇自偷自拍另欧美| 亚洲&#228;v永久无码精品天堂久久| 一道本不卡免费视频| 亚洲视频在线播放| 在线观看人成网站深夜免费| 一级做a爰片久久毛片免费看| 亚洲久本草在线中文字幕| 麻豆国产人免费人成免费视频 | 国产午夜亚洲精品不卡电影| 亚洲精品你懂的在线观看| 成人免费视频试看120秒| 国产男女爽爽爽免费视频 | 亚洲人成电影在线观看青青| 波多野结衣一区二区免费视频| 久久中文字幕免费视频| 国产成人人综合亚洲欧美丁香花| 无码乱人伦一区二区亚洲一| 日韩免费a级在线观看| 可以免费观看的毛片| 国产亚洲高清在线精品不卡 | 久久99精品免费一区二区| jlzzjlzz亚洲jzjzjz| 国产亚洲精品观看91在线| 欧洲精品免费一区二区三区| 久久国产精品免费网站| 一级做a爱过程免费视频高清| 亚洲综合色丁香婷婷六月图片| 久久久无码精品亚洲日韩蜜桃 | 女人18毛片特级一级免费视频| 两个人看的www高清免费视频| 亚洲码欧美码一区二区三区| 亚洲高清视频在线观看| 中文字幕中韩乱码亚洲大片| 免费人成在线观看网站品爱网日本| 91精品免费在线观看| 久久青草国产免费观看| 国产免费人成视频在线播放播| 国产亚洲高清在线精品不卡|