SHARE
TWEET

Untitled

a guest Aug 12th, 2016 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top