JDBC课堂总结

来源:互联网 发布:软件开发部年终总结 编辑:程序博客网 时间:2024/05/18 22:40

1、加载驱动

Class.forName();

2、通过驱动管理器获得连接

DriverManager.getConnection();

3、获得statement()或者preparedStatement();

connection.createStatement();

connection.preparedStatement();

4、通过statement修改/查询表格内容

statement.executeUpdate();  修改

statement.executeQuery();------->ResultSet 查询

5、关闭

close();


事务

connection.setAutoCommit(false); 关闭自动提交

rollback   回滚

commit   提交

个人总结:

1、executeQuery()方法得到的是一个类似于数组的结果集

所以要用Resultset类型的方法来接收,值得注意的是这个方法找出来的结果必须是满足条件的结果,比如:登陆程序中,条件若能在数据库中寻找到,则有值,否则

Resultset不会得到值。createStatement()方法中不能写查询条件,preparedStatement()方法可以写查询条件。

1 0
原创粉丝点击