Advertisement
Guest User

Untitled

a guest
Nov 25th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class Database {
  4.  
  5. private Connection conn = null; // <--- obiekt polaczenia
  6. private static final String USER = "root";
  7. private static final String PASS = "root";
  8.  
  9.  
  10. private static final String DB_URL = "jdbc:mysql://localhost/lab5";
  11. // jdbc <--- sterownik
  12. // mysql <--- dialekt sql / typ bazy
  13. // ://localhost/nowy"
  14.  
  15.  
  16. public void connect(){
  17. sout("Connecting to database...");
  18. conn = DriverManager.getConnection(DB_URL,USER,PASS); // <---
  19. sout("Connected");
  20. }
  21.  
  22. public void sendDoctorToDatabase(Doctor doctor){
  23.  
  24. try{
  25. Statement statement = conn.createStatement();
  26. String sql = "insert into doctors (name, surname) values "+
  27. + "('" + doctor.getName + "','" + doctors.getSurname() + "');";
  28. statement.execute(sql);
  29. }
  30. }
  31.  
  32.  
  33. public ArrayList<Doctor> getDoctorList(){
  34. ArrayList<Doctor> doctors = new ArrayList<>();
  35. try{
  36. Statement statement = conn.createStatement();
  37. String sql = "select * from doctors;"; // zapytanie
  38. ResultSet resultSet = statement.executeQuery(sql);
  39. while(resultSet.next()){
  40.  
  41.  
  42.  
  43. }
  44.  
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement