Guest User

Untitled

a guest
Jul 14th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.SQLException;
  4. import java.sql.Statement;
  5. import java.util.Scanner;
  6.  
  7. public class dodajpracownika {
  8.  
  9. static String url = "jdbc:mysql://127.0.0.1:3306/";
  10. static String baza = "pracownicy";
  11. static String login = "root"; // <---- podaj swój login
  12. static String password = "78963976"; // <---- podaj swoje hasło
  13.  
  14. public static void stworzTabele() {
  15. try {
  16. Connection conn = DriverManager.getConnection(url+baza, login, password);
  17. Statement st = conn.createStatement();
  18. try {
  19. String id;
  20. Scanner odczyt = new Scanner(System.in);
  21. id = odczyt.nextLine();
  22. String imie;
  23. Scanner odczyt2 = new Scanner(System.in);
  24. imie = odczyt2.nextLine();
  25. String nazwisko;
  26. Scanner odczyt3 = new Scanner(System.in);
  27. nazwisko = odczyt3.nextLine();
  28. String nowa_tabela = "CREATE TABLE ";
  29. nowa_tabela = nowa_tabela + id + " (" + imie + " VARCHAR(100), " + nazwisko + " VARCHAR(100)) DEFAULT CHARSET=cp1250 collate cp1250_polish_ci";
  30. st.executeUpdate(nowa_tabela);
  31. System.out.println("Tabela została utworzona");
  32. } catch (SQLException e) {
  33. System.out.println("Uwaga! Tabela już istnieje");
  34. }
  35. } catch (SQLException e) {
  36. System.out.println("Uwaga! Mamy problemy z połączeniem!");
  37. }
  38.  
  39. }
  40.  
  41. public static void main(String[] args) {
  42. stworzTabele();
  43. }
  44.  
  45. }
Add Comment
Please, Sign In to add comment