try{

a、导入驱动包、加载具体的驱动类Class.forName("具体的驱动类");

b、与数据库建立connection=DriverManager.getConnection(.....)

c、通过connection,获取操作数据库的对象(Statement\prepateStatement\callablestatement

如:stmt=connection.createStatement())

d、(查询)需要处理结果集rs=pstmt.executeQuery()

while(rs.next){rs.getXxx(.....)}

}catch(ClassNotFoundException e)

{...}

catch(SQLException e)

{....

}

catch(Exception e)

{...

}

fianlly

{

   //打开顺序,与关闭顺序相反

if(rs!=null)rs。close();

if (stmt!=null)  stmt.close();

if (connection!=null) connection.close();

}

--------jdbc中,除了Class.forName()抛出ClassNotFoundException,其余方法全部SQLException