Advertisement
Guest User

Untitled

a guest
Dec 18th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. public static void main(String[] args) throws SQLException, IOException, Exception {
  2.  
  3. Class.forName("org.postgresql.Driver");
  4. conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres", "postgres", "postgres");
  5. System.out.println("OK. Database is on.");
  6. conn.setAutoCommit(false);
  7. statmt = conn.createStatement();
  8. statmt.executeUpdate("CREATE TABLE 'Strongy'");
  9. conn.commit();
  10. conn.setAutoCommit(true);
  11. statmt.execute("INSERT INTO TAD (number) VALUES ('Petya'); ");
  12. statmt.execute("INSERT INTO TAD (number) VALUES ('Vasya'); ");
  13. statmt.execute("INSERT INTO TAD (number) VALUES ('Masha'); ");
  14. System.out.println("Таблица создана или уже существует.");
  15. resSet = statmt.executeQuery("SELECT * FROM TAD");
  16.  
  17. while(resSet.next())
  18. {
  19. int id = resSet.getInt("id");
  20. String name = resSet.getString("name");
  21. String phone = resSet.getString("phone");
  22. System.out.println( "ID = " + id );
  23. System.out.println( "name = " + name );
  24. System.out.println( "phone = " + phone );
  25. System.out.println();
  26. }
  27.  
  28. System.out.println("Таблица выведена");
  29.  
  30.  
  31. conn.close();
  32. statmt.close();
  33. resSet.close();
  34.  
  35. System.out.println("Соединения закрыты");
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement