基础部分:
一,load the driver
1,Classes.forName()|new Drivename();
2,实例化自动向DriverManager注册,不需要显示调用DriverManager.registerDriver方法;
二,connect to database
1,DriverManager.getconnection();
三,execute the SQL
1,connection.createStatement
2,Statement.executeQuery();
3,Statement.executeUpdate();
四,retrieve the result data
1,循环取得结果while(rs.next())
五,show the result data
1,将数据库中的各种类型的数据转化成java类型的数据,用get***()方法;
六,close
1,close the resultset2,close the statement 3,close the connection
进阶部分:
一:灵活指定SQL语句中的变量
PreparedStatement
二:对存储过程进行调用
CallableStatement
三:批处理
batch(只要创建一个statement即可,先addBatch,再executeBatch)
四:运用事务处理
transaction
五:回滚结果集
可以前后移动的结果集
ResultSet.TYPE_SCROLL_INSENSITIVE
ResultSet.CONCUR_READ_ONLY
六:可更新的结果集
ResultSet.CONCUR_UPDATABLE
七:DataSourse和RowSet
DataSourse:DriverManager的替代者
RowSet:新的ResultSet