时间不多了,这个方法不会写?
前不久才开始自学,自己边学边做一点东西,可下面这个方法不会写,高手能否指教一下?
数据库和界面上有2个格式完全一样的表格,怎样通过按钮事件把数据库表格里的数据输出到界面表格里面去呢?即使每个单元格都分别对应。
刚学,水平很菜的,在书上也没找到相关的可以参考,所以高手指导能否详细一点?
------解决方案--------------------先select * from [表]查出所有的数据,然后遍历这些数据就可以了
------解决方案--------------------DAO类
package petcol.DAO;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import petcol.conManager.*;
import petcol.jbean.*;
import java.util.ArrayList;
public class caseDAO {
conMan conmanager = new conMan();//得到conMan的实例,他里面有个得到Connection的方法
public boolean caseInsert(caseHistory cus) { //插入记录
Connection con = null;
PreparedStatement pstm = null;
try {
con = conmanager.GetCon();//得到connection
String sqlstr =
"insert into case_history(petname,loginname,doctorId,timeIn,symptom,rx) values(?,?,?,?,?,?) ";
pstm = con.prepareStatement(sqlstr);
pstm.setString(1, cus.getPetname());//给实体类值
pstm.setString(2, cus.getLoginname());
pstm.setString(3, cus.getDoctorId());
pstm.setString(4, cus.getTimeIn());
pstm.setString(5, cus.getSymptom());
pstm.setString(6, cus.getRx());
if (pstm.executeUpdate() == 1) {//如果返回记录条数为一,关闭连接,插入成功
con.close();
return true;
}
else {
con.close();
return false;
}
}
catch (Exception ex) {
ex.printStackTrace();
}
return false;
}
public boolean caseUpdate(caseHistory cus, String petname) {//以下类推
Connection con = null;
PreparedStatement pstm = null;
try {
con = conmanager.GetCon();
String sqlstr =
"update case_history set petname=?,loginname=?,doctorId=?,timeIn=?,symptom=?,rx=? where petname=? ";
pstm = con.prepareStatement(sqlstr);
pstm.setString(1, cus.getPetname());
pstm.setString(2, cus.getLoginname());
pstm.setString(3, cus.getDoctorId());
pstm.setString(4, cus.getTimeIn());
pstm.setString(5, cus.getSymptom());
pstm.setString(6, cus.getRx());
pstm.setString(7, petname);
if (pstm.executeUpdate() == 1) {
con.close();
return true;
}
else {
con.close();
return false;
}
}
catch (Exception ex) {
ex.printStackTrace();
return false;
}
}
public ArrayList caseSelect(String petname, String loginname) {
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
ArrayList list = new ArrayList();
try {
caseHistory casehitory = new caseHistory();
con = conmanager.GetCon();
String sqlstr =
"select * from case_history where petname=? and loginname=? ";
pstm = con.prepareStatement(sqlstr);
pstm.setString(1, petname);
pstm.setString(2, loginname);
rs = pstm.executeQuery();
if (rs.next()) {
casehitory.setPetname(rs.getString( "petname "));
casehitory.setLoginname(rs.getString( "loginname "));
casehitory.setDoctorId(rs.getString( "doctorId "));
casehitory.setTimeIn(rs.getString( "timeIn "));
casehitory.setSymptom(rs.getString( "symptom "));