Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package baza_danych;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.sql.ResultSet;
- import java.util.Scanner;
- /**
- *
- * @author Maciek
- */
- public class Baza_danych {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- String x; //w nim zapiszemy swoje imie
- Scanner odczyt = new Scanner(System.in); //obiekt do odebrania danych od użytkownika
- System.out.println("Wybierz liczbe");
- x = odczyt.nextLine();
- // TODO code application logic here
- switch(x) {
- case ("0"):
- try{
- String host = "jdbc:sqlserver://localhost:1433;databaseName=przychodnia";
- String uzytkownik = "sa";
- String haslo = "kasiaz";
- Connection con = DriverManager.getConnection(host,uzytkownik,haslo);
- Statement stmt = con.createStatement();
- String SQL = "SELECT * FROM lekarz";
- ResultSet rs = stmt.executeQuery(SQL);
- while (rs.next()){
- int nr_lekarza = rs.getInt("nr_lekarza");
- String imie = rs.getString("Imie");
- String nazwisko = rs.getString("Nazwisko");
- String telefon = rs.getString("telefon");
- String dostepnosc = rs.getString("dostepnosc");
- String p = nr_lekarza + " " + imie + " " + nazwisko + " " + telefon + " " + dostepnosc;
- System.out.println(p);
- }
- } catch(SQLException err){
- System.out.println(err.getMessage());
- }
- break;
- case ("1"):
- System.out.println("wybrales 1");
- break;
- case ("2"):
- try{
- String host = "jdbc:sqlserver://localhost:1433;databaseName=przychodnia";
- String uzytkownik = "sa";
- String haslo = "kasiaz";
- Connection con = DriverManager.getConnection(host,uzytkownik,haslo);
- Statement stmt = con.createStatement();
- String SQL = "SELECT * FROM pacjent";
- ResultSet rs = stmt.executeQuery(SQL);
- while (rs.next()){
- int nr_ubezpieczenia = rs.getInt("nr_ubezpieczenia");
- String imie = rs.getString("Imie");
- String nazwisko = rs.getString("Nazwisko");
- String telefon = rs.getString("telefon");
- String adres = rs.getString("adres");
- String p = nr_ubezpieczenia + " " + imie + " " + nazwisko + " " + telefon + " " + adres;
- System.out.println(p);
- }
- } catch(SQLException err){
- System.out.println(err.getMessage());
- }
- break;
- case ("3"):
- try{
- String host = "jdbc:sqlserver://localhost:1433;databaseName=przychodnia";
- String uzytkownik = "sa";
- String haslo = "kasiaz";
- Connection con = DriverManager.getConnection(host,uzytkownik,haslo);
- Statement stmt = con.createStatement();
- String SQL = "SELECT * FROM choroba";
- ResultSet rs = stmt.executeQuery(SQL);
- while (rs.next()){
- int nr_choroby = rs.getInt("nr_choroby");
- String objawy = rs.getString("objawy");
- String nazwa = rs.getString("Nazwa");
- String krotki_opis = rs.getString("krotki_opis");
- int id_leczenie = rs.getInt("id_leczenie");
- int id_lecz = rs.getInt("id_lecz");
- String p = nr_choroby + " " + objawy + " " + nazwa + " " + krotki_opis + " " + id_leczenie + " " + id_lecz;
- System.out.println(p);
- }
- } catch(SQLException err){
- System.out.println(err.getMessage());
- }
- case("4"):
- try{
- String host = "jdbc:sqlserver://localhost:1433;databaseName=przychodnia";
- String uzytkownik = "sa";
- String haslo = "kasiaz";
- Connection con = DriverManager.getConnection(host,uzytkownik,haslo);
- Statement stmt = con.createStatement();
- String SQL = "SELECT * FROM leczenie";
- ResultSet rs = stmt.executeQuery(SQL);
- while (rs.next()){
- int nr_choroby = rs.getInt("id_leczenia");
- String objawy = rs.getString("zalecanie");
- String nazwa = rs.getString("ile");
- String krotki_opis = rs.getString("jak_czesto");
- String p = nr_choroby + " " + objawy + " " + nazwa + " " + krotki_opis;
- System.out.println(p);
- }
- } catch(SQLException err){
- System.out.println(err.getMessage());
- }
- break;
- case ("5"):
- try{
- String w;
- w = odczyt.nextLine();
- String host = "jdbc:sqlserver://localhost:1433;databaseName=przychodnia";
- String uzytkownik = "sa";
- String haslo = "kasiaz";
- Connection con = DriverManager.getConnection(host,uzytkownik,haslo);
- Statement stmt = con.createStatement();
- String SQL = "DELETE FROM leczenie WHERE nr_choroby = '"+w+"'";
- stmt.executeUpdate(SQL);
- } catch(SQLException err){
- System.out.println(err.getMessage());
- }
- break;
- case ("6"):
- try{
- String nr_ubezpieczenia;
- nr_ubezpieczenia = odczyt.nextLine();
- String imie;
- imie = odczyt.nextLine();
- String nazwisko;
- nazwisko = odczyt.nextLine();
- String telefon;
- telefon = odczyt.nextLine();
- String adres;
- adres = odczyt.nextLine();
- String host = "jdbc:sqlserver://localhost:1433;databaseName=przychodnia";
- String uzytkownik = "sa";
- String haslo = "kasiaz";
- Connection con = DriverManager.getConnection(host,uzytkownik,haslo);
- Statement stmt = con.createStatement();
- String SQL = "INSERT INTO pacjent VALUES ('"+nr_ubezpieczenia+"', '"+imie+"','"+nazwisko+"','"+telefon+"','"+adres+"')";
- stmt.executeUpdate(SQL);
- System.out.println("Inserted records into the table...");
- } catch(SQLException err){
- System.out.println(err.getMessage());
- }
- break;
- case("7"):
- try{
- String id_wizyty;
- id_wizyty = odczyt.nextLine();
- String data;
- data = odczyt.nextLine();
- String choroba;
- choroba = odczyt.nextLine();
- String nr_ubezpieczenia_pacjenta;
- nr_ubezpieczenia_pacjenta = odczyt.nextLine();
- String id_lekarza;
- id_lekarza = odczyt.nextLine();
- String id_choroby;
- id_choroby = odczyt.nextLine();
- String host = "jdbc:sqlserver://localhost:1433;databaseName=przychodnia";
- String uzytkownik = "sa";
- String haslo = "kasiaz";
- Connection con = DriverManager.getConnection(host,uzytkownik,haslo);
- Statement stmt = con.createStatement();
- String SQL = "INSERT INTO pacjent VALUES ('"+id_wizyty+"', '"+data+"','"+choroba+"','"+nr_ubezpieczenia_pacjenta+"','"+id_lekarza+"','"+id_choroby+"')";
- stmt.executeUpdate(SQL);
- System.out.println("Inserted records into the table...");
- } catch(SQLException err){
- System.out.println(err.getMessage());
- }
- break;
- case("8"):
- try{
- String set;
- set = odczyt.nextLine();
- String wartosc;
- wartosc = odczyt.nextLine();
- String warunek;
- warunek = odczyt.nextLine();
- String wartosc_war;
- wartosc_war = odczyt.nextLine();
- String host = "jdbc:sqlserver://localhost:1433;databaseName=przychodnia";
- String uzytkownik = "sa";
- String haslo = "kasiaz";
- Connection con = DriverManager.getConnection(host,uzytkownik,haslo);
- Statement stmt = con.createStatement();
- String SQL = "update pacjent set imie = '"+wartosc+"' where adres = '"+wartosc_war+"'";
- stmt.executeUpdate(SQL);
- System.out.println("Inserted records into the table...");
- } catch(SQLException err){
- System.out.println(err.getMessage());
- }
- break;
- default:
- System.out.println("zle");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement