Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1.  
  2.  
  3.  
  4. import java.sql.*;
  5.  
  6.  
  7. public class JEELab1 {
  8.  
  9. public static final String JDBC_URL="jdbc:derby:D://localhost:1527/jee34;user=student;password=wcy";
  10. public static final String QUERY = "SELECT * FROM student.uzytkownicy";
  11.  
  12.  
  13. public static void main(String[] args) throws SQLException
  14. {
  15. Connection conn = DriverManager.getConnection(JDBC_URL);
  16. System.out.println("Polaczono");
  17.  
  18. Statement stat = conn.createStatement();
  19. ResultSet rs = stat.executeQuery(QUERY);
  20.  
  21. System.out.println("\nNazwisko\tImie\t(ID)");
  22. while(rs.next())
  23. {
  24. System.out.println(rs.getString("NAZWISKO")+ "\t\t"
  25. + rs.getString("IMIE") + "\t\t("
  26. + rs.getString("ID") + ")");
  27.  
  28. }
  29.  
  30. if(stat != null)
  31. {
  32. stat.close();
  33. }
  34. if(conn != null)
  35. {
  36. conn.close();
  37. }
  38.  
  39. System.out.println("\nRozlaczono");
  40. }
  41.  
  42. }
  43.  
  44. public static Connection getConn() {
  45. return conn;
  46. }
  47.  
  48. private MyConn(){};
  49. public static boolean Polacz() throws SQLException
  50. {
  51. conn=DriverManager.getConnection(JDBC_URL);
  52. if (conn==null)
  53. {
  54. return false;
  55. }
  56. else
  57. {
  58. return true;
  59. }
  60. };
  61. public static boolean Rozlacz() throws SQLException
  62. {
  63. if (conn==null)
  64. {
  65. return false;
  66. }
  67. else
  68. {
  69. conn.close()
  70. return true;
  71. }
  72. }
  73.  
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement