Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1.  
  2. package javaapplication2;
  3.  
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9. import java.util.Properties;
  10.  
  11. /**
  12. *
  13. * @author bocinec3
  14. */
  15. public class JavaApplication2 {
  16.  
  17. public static void strankovanie(int strana,int pocetNaStranu ){
  18.  
  19. String url = "jdbc:postgresql://db.ii.fmph.uniba.sk/db1";
  20. // Properties je mapa kluc->hodnota
  21. Properties properties = new Properties();
  22. properties.put("user", "bocinec3@uniba.sk");
  23. properties.put("password", "db1bocinec3");
  24.  
  25.  
  26. try(Connection connection = DriverManager.getConnection(url,properties)){
  27. System.out.println("som prihlaseny ");
  28. Statement statement = connection.createStatement();
  29. String query= "SELECT * from employees offset "+Integer.toString(strana*pocetNaStranu)+" limit "+Integer.toString(pocetNaStranu);
  30. ResultSet res = statement.executeQuery(query);
  31. while(res.next()){
  32. System.out.println(res.getString("first_name"));
  33. }
  34.  
  35. }
  36. catch(Exception e){
  37. e.printStackTrace();
  38. }
  39. }
  40. public static void main(String[] args) throws SQLException {
  41. strankovanie(1,10);
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement