的JDBC Tutorial是一個很好的起點
一個片段從前奏
The JDBC API is a Java API that can access any kind of tabular data,
especially data stored in a Relational Database.
JDBC helps you to write java applications that manage these three programming
activities:
1. Connect to a data source, like a database
2. Send queries and update statements to the database
3. Retrieve and process the results received from the database in answer to
your query
The following simple code fragment gives a simple example of
these three steps:
Connection con = DriverManager.getConnection
("jdbc:myDriver:wombat", "myLogin","myPassword");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table1");
while (rs.next()) {
int x = rs.getInt("a");
String s = rs.getString("b");
float f = rs.getFloat("c");
}
This short code fragment instantiates a DriverManager object to
connect to a database driver and log into the database, instantiates a
Statement object that carries your SQL language query to the database;
instantiates a ResultSet object that retrieves the results of your query,
and executes a simple while loop, which retrieves and displays those
results. It's that simple.
還有上谷歌圖書here一本書預覽。
使用它之後,我發現現在這實際上並不是最好的教程。我可能是錯的,但是在介紹的東西出現之後,有些部分指令遺漏了,據說會逐步實現事情的工作方式。在我更換教程之前,我必須自己推斷大部分內容。 – 2008-11-21 17:38:38