简述JDBC调用数据库的基本步骤

//1.注册驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
//2.获取连接
Connection conn = DriverManager.getConnection("jdcc:oracle:thin:@localhost:1506:Alfred","root","root");
//3.获取能够发送sql语句的对象
Statement st = conn.createStatement();
//4.执行sql语句
ResultSet rs = st.executeQuery(sql);
//5.有结果集处理结果集
while(rs.next){
System.out.println(rs.getInt("id")+"  "+rs.getName("name"));
}
//6.关闭资源
if(rs!=null){
rs.close();
}
if(st!=null){
st.close();
}
if(conn!=null){
conn.close();
}

你可能感兴趣的:(简述JDBC调用数据库的基本步骤)