## JDBC编程六步
```java
import java.sql.*;
public class Test01{
public static void main(String[] args){
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/qzj","root","333");
stmt = conn.createStatement();
String sql = "select ename from emp";
rs = stmt.executeQuery(sql);
while(rs.next()){
String ename = rs.getString("ename");
System.out.println(ename);
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(rs != null){
try{
rs.close();
}catch(Exception e){
e.printStackTrace();
}
}
if(stmt != null){
try{
stmt.close();
}catch(Exception e){
e.printStackTrace();
}
}
if(conn!= null){
try{
conn.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
}
}
import java.sql.*;
public class Test02{
public static void main(String[] args){
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/qzj","root","333");
stmt = conn.createStatement();
String sql = "select ename from emp";
rs = stmt.executeQuery(sql);
while(rs.next()){
String ename = rs.getString("ename");
System.out.println(ename);
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(rs != null){
try{
rs.close();
}catch(Exception e){
e.printStackTrace();
}
}
if(stmt != null){
try{
stmt.close();
}catch(Exception e){
e.printStackTrace();
}
}
if(conn!= null){
try{
conn.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
}
}