//陣列寫法
package com.hellopianoman.salarytestdb;
import java.sql.*;
public class SalaryTest {
public static void main(String[] args) throws Exception {
DataAccessObject dao = new DataAccessObject("com.mysql.jdbc.Driver", "jdbc:mysql://127.0.0.1/hr?user=root&password=");
String[][] emp = dao.getEmployee();
int[][] lev = dao.getLevel();
int salary=0;
for(int i=0; i<emp.length; i++){
for(int j=0; j<lev.length; j++)
if(lev[j][0]==Integer.parseInt(emp[i][3]))
salary=lev[j][1]+Integer.parseInt(emp[i][4])*lev[j][2];
System.out.println("本薪:"+salary);
}
}
}
//物件導向(OO)寫法
package com.hellopianoman.salarytestdb;
import java.sql.*;
public class SalaryTest {
public static void main(String[] args) throws Exception {
DataAccessObject dao = new DataAccessObject("com.mysql.jdbc.Driver", "jdbc:mysql://127.0.0.1/hr?user=root&password=");
Employee[] emp = dao.getEmployee();
Level lev = dao.getLevel();
int salary = 0;
for (int i = 0; i < emp.length; i++) {
salary = lev.getSalary(emp[i].get職等(), emp[i].get職級());
System.out.println("本薪:" + salary);
}
}
}
留言列表