Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamRuth01 committed Mar 14, 2024
1 parent 9a94a3e commit bee4f81
Show file tree
Hide file tree
Showing 8 changed files with 613 additions and 125 deletions.
124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 29 additions & 15 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class Main {
static CustomersMGR customersMGR = new CustomersMGR();
static MobileDevicesMGR mobileDevisesMGR = new MobileDevicesMGR();
static MobileDevicesMGR mobileDevicesMGR = new MobileDevicesMGR();
static ReparationsMGR reparationsMGR = new ReparationsMGR();
public static void main(String[] args) throws SQLException {
menu();
Expand Down Expand Up @@ -46,9 +46,9 @@ private static void menuSelection(int selection) throws SQLException {
customersMGR.crudCustomersMenu();
break;
case 2:
MobileDevicesMGR.crudMobileDevisesMenu();
mobileDevicesMGR.crudMobileDevicesMenu();
break;
case 3: ReparationsMGR.crudReparationMenu();
case 3: reparationsMGR.crudReparationMenu();
break;
case 4:
CustomerDemo.customerMenu();
Expand Down
33 changes: 24 additions & 9 deletions src/main/java/org/example/manager/CustomersMGR.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void insert(Customer obj){
pstmt.setString(2, obj.getPhoneNumber());
pstmt.setString(3, obj.getAddress());
pstmt.executeUpdate();
System.out.println("En post har lagts till i tabellen.");
System.out.println("The post has been inserted.");
} catch (SQLException e) {
System.out.println("Failed during insert statement");
e.printStackTrace();
Expand Down Expand Up @@ -140,11 +140,25 @@ private void updateDataIntoTable() {
System.out.print("Enter the new name: ");
String name = scanner.nextLine();
obj.setName(name);
String sql = "UPDATE customers SET customer_name = ?, customer_phone_number WHERE customer_id = ?;";
System.out.println("Enter the new phone number: ");
String phoneNumber = scanner.nextLine();
obj.setPhoneNumber(phoneNumber);
System.out.println("Enter address: ");
String address = scanner.nextLine();
obj.setAddress(address);

String sql = "UPDATE customers SET customer_name = ?, customer_phone_number = ?,customer_adress = ? WHERE customer_id = ?;";
try (Connection conn = getConnection(url, username, password);
PreparedStatement pstmt = conn.prepareStatement(sql)) {
pstmt.setString(1, obj.getName());
pstmt.setInt(2, obj.getId());
pstmt.setString(2, obj.getPhoneNumber());
pstmt.setString(3, obj.getAddress());
pstmt.setInt(4, obj.getId());
System.out.println("The updated ID: "+ obj.getId());
System.out.println( "The updated name: "+ obj.getName());
System.out.println("The updated phone number: " + obj.getPhoneNumber());
System.out.println("The updated address: " + obj.getAddress());

int affectedRows = pstmt.executeUpdate();
System.out.println(affectedRows + " poster uppdaterades.");
} catch (SQLException e) {
Expand All @@ -155,20 +169,21 @@ private void updateDataIntoTable() {


private void deleteDataFromTable() {
Customer obj = new Customer();
Scanner scanner = new Scanner(System.in);
System.out.print("Chose customer_id to delete: ");
int id = scanner.nextInt();

obj.setId(id);
String sql = "DELETE FROM customers WHERE customer_id = ?;";

try (Connection conn = getConnection(url, username, password);
PreparedStatement pstmt = conn.prepareStatement(sql)) {

pstmt.setInt(1, id);
pstmt.setInt(1, obj.getId());
int affectedRows = pstmt.executeUpdate();
System.out.println(affectedRows + " poster uppdaterades.");
System.out.println("You deleted id: " + obj.getId());
System.out.println(affectedRows + " deleted success!");
// Ska jag ta bort affeted rows?
} catch (SQLException e) {
System.out.println("Kunde inte uppdatera data.");
System.out.println("Could not delete inserted data.");
e.printStackTrace();
}

Expand Down
Loading

0 comments on commit bee4f81

Please sign in to comment.