Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class main {
- public static void main(String[] args) {
- System.out.println("Wpisz zapytanie do bazy: ");
- Scanner scanner = new Scanner(System.in);
- connect(scanner.nextLine());
- }
- static void connect(String select) {
- Connection con;
- Statement stmt;
- try {
- String host = "jdbc:oracle:thin:@155.158.112.45:1521:oltpstud";
- String uzytkownik = "ziibd12";
- String haslo = "haslo2";
- con = DriverManager.getConnection(host, uzytkownik, haslo);
- stmt = con.createStatement();
- String[] tab = select.split(" ");
- System.out.println(tab[0]);
- try {
- if (tab[0].equals("select")) {
- ResultSet rs = stmt.executeQuery(select);
- while (rs.next()) {
- showResults(rs);
- }
- } else if (tab[0].equals("insert")) {
- stmt.executeUpdate(select);
- System.out.println("Update wykonany pomyślnie.");
- } else {
- System.out.println("Wpisałeś złe polecenie, spróbuj ponownie ");
- }
- } catch (Exception e) {
- System.out.println(" Zła kostrukcja polecenia");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement