JDBC基礎學習,jdbc基礎

來源:互聯網
上載者:User

JDBC基礎學習,jdbc基礎

1.概念:java資料庫連接技術

2.JDBC:是一個規範,提供介面(面向介面編程)

3.JDBC API:提供者員調用的介面和類,整合在java.sql 和javax.sql包中。如:DriverManager類(管理不同的JDBC驅動)、Connerction介面、Statement介面、ResultSet介面

4.JDBC API主要功能:與資料庫建立串連、執行SQL語句、處理結果

5.三大介面:

 

  <1>Connerction介面:負責串連資料庫並擔任傳輸資料的任務

 

  <2>Statement介面: 由Connection產生、負責執行SQL語句

 

  <3>ResultSet介面: 負責保持Statement執行後產生的查詢結果

6.JDBC工作的主要步驟:

 

  《一》、載入JDBC驅動

 

    Class.forName(JDBC驅動類);

 

  《二》、與資料庫建立串連

 

     Connection conn = Drivermanager.getConnection(URL,資料庫使用者名稱,密碼);

 

  《三》、發送SQL語句,並得到返回結果

 

    Statement stmt = conn.creteStatement();

 

    ResultSet rs = stmt = executeQuery(“SELECT a FROM  Table1”);

 

  《四》、處理結果

 

    While(rs.next()){

 

      Int x rs.getInt(“a”);

 

    }

 

  《五》、釋放資源

 

    rs.close();

 

    stmt.close();

 

    conn.close();

 

模板

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.