Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1.  
  2. public class main {
  3.  
  4. public static void main(String[] args) {
  5.  
  6. System.out.println("Wpisz zapytanie do bazy: ");
  7. Scanner scanner = new Scanner(System.in);
  8. connect(scanner.nextLine());
  9.  
  10. }
  11.  
  12. static void connect(String select) {
  13.  
  14. Connection con;
  15. Statement stmt;
  16.  
  17. try {
  18. String host = "jdbc:oracle:thin:@155.158.112.45:1521:oltpstud";
  19. String uzytkownik = "ziibd12";
  20. String haslo = "haslo2";
  21. con = DriverManager.getConnection(host, uzytkownik, haslo);
  22. stmt = con.createStatement();
  23. String[] tab = select.split(" ");
  24. System.out.println(tab[0]);
  25. try {
  26. if (tab[0].equals("select")) {
  27. ResultSet rs = stmt.executeQuery(select);
  28. while (rs.next()) {
  29. showResults(rs);
  30. }
  31. } else if (tab[0].equals("insert")) {
  32. stmt.executeUpdate(select);
  33. System.out.println("Update wykonany pomyślnie.");
  34. } else {
  35. System.out.println("Wpisałeś złe polecenie, spróbuj ponownie ");
  36. }
  37. } catch (Exception e) {
  38. System.out.println(" Zła kostrukcja polecenia");
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement