Advertisement
Guest User

Untitled

a guest
Aug 12th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. public static void main(String[] args) {
  2. try {
  3. Class.forName("org.postgresql.Driver");
  4.  
  5. Connection con=DriverManager.getConnection("jdbc:postgresql://localhost:5432/dvdrental2","postgres","vibhug");
  6. System.out.println("Opened database successfully");
  7.  
  8.  
  9. Statement st=con.createStatement();
  10. ResultSet rs=st.executeQuery("select * from actor ");
  11.  
  12. while(rs.next())
  13. {
  14. int actor_id = rs.getInt("actor_id");
  15. String first_name = rs.getString("first_name");
  16. int last_name = rs.getInt("last_name");
  17.  
  18. System.out.println( "ID = " + actor_id );
  19. System.out.println( "fNAME = " + first_name );
  20. System.out.println( "AGE = " + last_name );
  21.  
  22. System.out.println();
  23.  
  24. }
  25. con.close();
  26.  
  27.  
  28.  
  29. } catch (ClassNotFoundException | SQLException e) {
  30. // TODO Auto-generated catch block
  31. e.printStackTrace();
  32. }
  33. System.out.println("operation done successfully!!!");
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement