import javax.swing.*; import java.sql.*; import java.awt.*; import java.awt.event.*; import javax.swing.table.DefaultTableModel;
public class C extends JFrame { public static void main(String[] args) throws Exception { DataBase db=new DataBase(); db.accessData(); DataItem[] item=new DataItem[100]; for(int i=0;i<100;i++) { item[i]=new DataItem(); System.out.println(item[i].getEmployeeName() ); } } }
class DataBase { public DataItem[] accessData() throws Exception { Connection cn; Statement sql; ResultSet rs; String url="jdbc:odbc:myDataBase"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); cn=DriverManager.getConnection(url); sql=cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); String str="select * from WorkTime"; rs=sql.executeQuery(str); DataItem[] item=new DataItem[100]; for(int i=0;i<100;i++) { item[i]=new DataItem(); } int j=0; while(rs.next()) { item[j].setEmployeeID(rs.getString("EmployeeID")); item[j].setEmployeeName(rs.getString("EmployeeName")); item[j].setOnWorkTime(rs.getString("OnworkTime")); item[j].setOffWorkTime(rs.getString("offworkTime")); item[j].setLeaveWorkTime(rs.getString("LeaveworkTime")); item[j].setDescribe(rs.getString("Describe")); j++; } rs.close(); sql.close(); cn.close(); //System.out.println(item[2].getEmployeeName() ); return item; } } class DataItem { private String employeeID; private String employeeName; private String onWorkTime; private String offWorkTime; private String leaveWorkTime; private String describe; public void setEmployeeID(String employeeID) { this.employeeID=employeeID; } public void setEmployeeName(String employeeName) { this.employeeName=employeeName; } public void setOnWorkTime(String onWorkTime) { this.onWorkTime=onWorkTime; } public void setOffWorkTime(String offWorkTime) { this.offWorkTime=offWorkTime; } public void setLeaveWorkTime(String leaveWorkTime) { this.leaveWorkTime=leaveWorkTime; } public void setDescribe(String describe) { this.describe=describe; } //-------------------------------------------------------------------- public String getEmployeeID() { return employeeID; } public String getEmployeeName() { return employeeName; } public String getOnWorkTime() { return onWorkTime; } public String getOffWorkTime() { return offWorkTime; } public String getLeaveWorkTime() { return leaveWorkTime; } public String getDescribe() { return describe; }
} 为什么数据库中的内容不能传递过主函数了。。是什么问题。。谢谢