안녕하세요. 원한다면 Console에 데이터베이스 테이블의 전체 내용을 표시하는 것이 좋습니다. 내가 먼저 데이터베이스에서 레코드를 가져오고 ArrayList를 보관하려고하지만 어떤 일이이 표시 insted 표시되지 않습니다ArrayList를 사용하여 데이터베이스에서 내 콘솔의 모든 데이터를 표시하려고합니다.
[[email protected]]
[[email protected], [email protected]]
[[email protected], [email protected], [email protected]]
내가 무엇을해야하는지 완전히 혼란 스러워요. 내 코드는 다음과 같습니다
EmployeeDTO java file
public class EmployeeDTO
{
//private properties
private int empNo;
private String eName;
private String jobTitle;
//setters
public void setEmpNo(int val){empNo=val;}
public void setEName(String val){eName=val;}
public void setJob(String val){jobTitle=val;}
// getters
public int getEmpNo(){return empNo;}
public String getEName(){return eName;}
public String getJob(){return jobTitle;}
}
내에는 EmployeeList 자바 코드는 다음과 같습니다
public class EmployeeList
{
public static void main(String argv[])
{
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try
{
// Load the JDBC driver
// This can be skipped for Derby, but derbyclient.jar has to be in the CLASSPATH
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String accessFileName = "E:/Database/java";
conn=DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ="+accessFileName+".accdb;");
// Build an SQL String
String sqlQuery = "SELECT * from Employee";
// Create a Statement object
stmt = conn.createStatement();
// Execute SQL and get obtain the ResultSet object
rs = stmt.executeQuery(sqlQuery);
ArrayList<EmployeeDTO> employees = new ArrayList<EmployeeDTO>();
// Process the result set - print Employees
while (rs.next())
{
EmployeeDTO currentEmp = new EmployeeDTO();
currentEmp.setEmpNo(rs.getInt("EMPNO"));
currentEmp.setEName(rs.getString("ENAME"));
currentEmp.setJob(rs.getString("JOB_TITLE"));
employees.add(currentEmp);
System.out.println(employees);
}
}
catch(SQLException se)
{
System.out.println ("SQLError: " + se.getMessage()+ " code: " + se.getErrorCode());
}
catch(Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
finally
{
// clean up the system resources
try
{
rs.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
내 데이터베이스입니다 :
Employee
EMPN ENAME JOB_TITLE
1 abc xyz
2 pqr mno
3 lmn hij
이 제발 도와주세요 내가 오전 내 전체 코드 및 데이터베이스 을 게시 콘솔에 표시하는 방법이 잘못되었습니다.
while 루프 후이 작업을 수행 다음에 스스로 질문을 향상시킬 수 있습니다. – Jonathan