1.首先Class.forName("com.oracle.....");
调用驱动,这个其实是对这个驱动类做类的初始化。
2. DriverManager。getConnection(url,useraname,password);
建立连接,不建议用这个方法,因为这个不是连接池方式,建议使用DataSource数据源方式
3 Connection。prepareStatement("select * from table");
建立sql语句,不要使用statement语句,防止sql注入
4 执行
ResultSet rs=pst.executeQuery();
执行查询,建议使用缓存或者进行分页,不然会影响性能
5 While(rs.next)
{
String str=rs.getString(1);
}
rs。close()
pst。close()
从结果集取出记录,建议查询或更改时快速关闭资源,不要长时间占用资源,影响性能