Java資料庫操作

來源:互聯網
上載者:User

標籤:

一、JDBC

1.JDBC

           Java資料庫連接,用於Java程式中實現資料庫操作功能,java.sql包中提供了執行SQL語句,訪問各種資料庫的方法,並為各種不同的資料庫提供統一的操作介面及類。

2.操作步驟

  1. 載入JDBC磁碟機,將JDBC驅動載入到classpath中。
  2. 載入JDBC驅動,並將其註冊到DriverManager中。一般使用反射機制class.forName(String driverName)
  3. 建立資料庫連接,取得Connection對象。一般通過DriverManager.getConnection(url,username,passwd)方法實現,其中url表示串連資料庫的字串,uaername表示串連資料庫的使用者名稱,passwd表示串連資料庫的密碼。
  4. 建立Statement對象或PrepareStatement對象。
  5. 執行SQL語句。
  6. 訪問結構集ResultSet對象。
  7. 依次訪問ResultSet、Statement、PreparedStatement、Connection對象關閉,釋放掉所佔用的資源。

3.舉例舉出一個用訪問MySQL的例子

二、JDBC處理事務採用的方法

Java資料庫操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.