首页 > 代码库 > JDBC编程

JDBC编程

简单地说,JDBC 可做三件事:与数据库建立连接、发送 SQL 语句并处理结果。下列代码段给出了以上三步的基本示例:

Connection con = DriverManager.getConnection("jdbc:odbc:wombat","login", "password");

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");

}

JDBC编程