JDBC编程步骤

1. Load the Driver

1. Class.forName() | Class.forName().newInstance() | new DriverName()

2. 实例化时自动向DriverManager注册,不需显式调用DriverManager.registerDriver方法

2. Connect to the DataBase

DriverManager.getConnection()

3. Execute the SQL

1. Connection.CreateStatement()

2. Statement.executeQuery()

3. Statement.executeUpdate()

4. Retrieve the result data

循环去的结果 while(rs.next())

5. Show the result data

将数据库中的各种类型转换为Java中的类型(getXXX方法)

6. Close

1. close the resultSet;

2. close the statement;

3. close the connection;

猜你喜欢

转载自nudtgk2000.iteye.com/blog/1675523