Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. Connection conn = null;
  2. PreparedStatement pstmt = null;
  3. ResultSet rs = null;
  4.  
  5. try{
  6. DriverManager.registerDriver(new com.mysql.jdbc.Driver());
  7. conn = DriverManager.getConnection("jdbc:mysql://localhost/DB명", "ID", "PWD");
  8. pstmt = conn.prepareStatement("SQL");
  9. rs = pstmt.executeQuery();
  10. while(rs.next()){
  11. writer.println(rs.getInt("col1") + ", " + rs.getString("col2") + "<br>");
  12. }
  13. }catch(Exception e){
  14. e.printStackTrace();
  15. }finally{
  16. try{ if(rs != null){ rs.close();} }catch(Exception e){}
  17. try{ if(pstmt != null){ pstmt.close();} }catch(Exception e){}
  18. try{ if(conn != null){ conn.close();} }catch(Exception e){}
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement