Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package System;
- import java.sql.SQLException;
- import java.util.Scanner;
- import Menu.DataAccess;
- public class Varesalg {
- Scanner sc = new Scanner(System.in);
- //load dataaccess
- DataAccess da = new DataAccess();
- public void salg() {
- String varenummer;
- int stk;
- int samlet = 0;
- //Indtast varenummer for solgte vare
- do{
- System.out.print("Indtast varenummer for solgte vare: ");
- while (!sc.hasNext()) {
- System.out.print("Du har indtastet ugyldigt nummer, prøv igen: \n");
- sc.nextLine();
- }
- varenummer = sc.nextLine();
- } while(varenummer == null);
- //Indtast antal vare der er solgt
- do{
- System.out.print("Indtast antal solgte enheder for varen " + varenummer + ": ");
- while (!sc.hasNextInt()) {
- System.out.print("Du har indtastet ugyldigt nummer, prøv igen: \n");
- sc.nextLine();
- }
- stk = sc.nextInt();
- } while(stk == 0);
- //Execute SQL statement
- String checkvarenummer = "SELECT stk from varetabel WHERE varenummer ='" + varenummer + "'";
- String salg = "update varetabel set stk = '" + samlet + "' WHERE varenummer ='" + varenummer + "'";
- // Execute SQL command "checkvarenummer"
- Object[][] x;
- int antal;
- try {
- x = da.executeQuery(checkvarenummer);
- for (Object[] o : x)
- {
- System.out.print(o[0]);
- if(x.length == 1)
- {
- }else
- {
- System.out.print("Det indtastede varenummer findes ikke");
- }
- }
- }catch (SQLException e) {
- e.printStackTrace();
- }
- // Execute SQL command "salg"
- try
- {
- da.executeUpdate(salg);
- {
- System.out.print("Antal for varen er ændret");
- }
- }catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement