-1

I am making a java app and i have some trouble while importing data from sql server to java arraylists. The database has some inserts and when i run main in java i am calling a method that does the jdbc and is filling some arraylists with data. The jdbc has been done succesfully but when I am checking the department of an Employee (Manager, deposit manager etc...) it appears that the program doesn't even check the if... else if... else if.... blocks. In sql String variables are written as VARCHAR(40)...


    Connection dbcon ;
            Statement stmt;
                try {
                dbcon = DriverManager.getConnection(url);
                stmt = dbcon.createStatement();

                String s = ("SELECT * FROM Employee");
                ResultSet rs = stmt.executeQuery(s);
                while (rs.next()) {
                    String f = rs.getString("fullname");
                    int id = rs.getInt("idEmployee");
                    String d = rs.getString("department");
                    String e = rs.getString("email");
                    double sa = rs.getDouble("salary");
                    Date da = rs.getDate("firstDate");
                    int l = rs.getInt("leaves");
                    String u = rs.getString("username");
                    String p = rs.getString("password");
                    double o = rs.getDouble("overall");

                    if (d == "Manager") {
                        new Manager (f, id, d, e, sa, da, l, u, p, o);
                    } else if (d == "Loan Manager") {
                        new LoanManager(f, id, d, e, sa, da, l, u, p, o);                   
                    } else if (d == "Deposit Manager") {
                        new DepositManager(f, id, d, e, sa, da, l, u, p, o);
                    } else if (d == "Private Customer Manager" ) {
                        new PrivateCustomerManager(f, id, d, e, sa, da, l, u, p, o);

Is there anything i can do to fix this problem?

Vicky K.
  • 7
  • 3

1 Answers1

0

Try to use .equals() string method.

if (d.equals("Manager")) {
    new Manager (f, id, d, e, sa, da, l, u, p, o);
} else if (d.equals("Loan Manager")) {
    new LoanManager(f, id, d, e, sa, da, l, u, p, o);                   
} else if (d.equals("Deposit Manager")) {
    new DepositManager(f, id, d, e, sa, da, l, u, p, o);
} else if (d.equals("Private Customer Manager")) {
    new PrivateCustomerManager(f, id, d, e, sa, da, l, u, p, o);
Jose Esparza
  • 292
  • 1
  • 8