将bean对象里的值一次插入数据库 50

我现在做好了bean,里边属性和表中列名一致,在页面传值给一个类后我把数据保存到了bean里边.然后我想再写个方法把bean做为对象传过去.然后把数据保存到数据库.请高手... 我现在做好了bean,里边属性和表中列名一致,在页面传值给一个类后我把数据保存到了bean里边.然后我想再写个方法把bean做为对象传过去.然后把数据保存到数据库.

请高手指教..我是菜鸟..谢谢
关键点在于..在这个类中我不知道该怎么引用bean.怎么能把bean的属性保存到数据库.而且要同用.不管是哪个bean都能这么做..
哪为高手能给写个小例子..
如果被采纳追加30分..谢谢
展开
 我来答
yan007007
2008-10-12 · TA获得超过313个赞
知道小有建树答主
回答量:458
采纳率:0%
帮助的人:273万
展开全部
说点大白话~~呵呵。单独做个操作数据库的类,在这个类中引用bean。能明白吧
给你个以前工作的例子。。

这个是BEAN
package cn.ccnp.area;

import java.io.Serializable;
public class Area implements Serializable {

/**
* 区域ID
*/
private String areaId;

/**
* 区域名称
*/
private String areaName;

/**
* 所属区县
*/
private String areaFatherId;

/**
* 所属省市
*/
private String areaGrandfatherId;

/**
* 区域ID getter,setter method
*/
public String getAreaId( ){
return areaId;
}

public void setAreaId( String areaId ){
this.areaId = areaId;
}

/**
* 区域名称 getter,setter method
*/
public String getAreaName( ){
return areaName;
}

public void setAreaName( String areaName ){
this.areaName = areaName;
}

/**
* 所属区县 getter,setter method
*/
public String getAreaFatherId( ){
return areaFatherId;
}

public void setAreaFatherId( String areaFatherId ){
this.areaFatherId = areaFatherId;
}

/**
* 所属省市 getter,setter method
*/
public String getAreaGrandfatherId( ){
return areaGrandfatherId;
}

public void setAreaGrandfatherId( String areaGrandfatherId ){
this.areaGrandfatherId = areaGrandfatherId;
}
}

这个是对数据库的操作。懒得挑了。。都粘过来,你自己看吧,有些是公司内部的类,不用都明白哈~~
package cn.ccnp.area;

/**
* <p>Title: AreaMgrImpl</p>
* <p>Description: area implement</p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: jadosoft</p>
* @author Yangyang
* @version 1.0
*/

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import org.apache.log4j.Logger;

import cn.jado.app.log.OperatorLog;
import cn.jado.app.log.OperatorLogger;
import cn.jado.lib.QuoteReplace;
import cn.jado.lib.web.CommonDAO;
import cn.jado.lib.web.Page;
import cn.jado.lib.web.PageDiv;

public class AreaMgrImpl {

/**
* Constructor
*/
public AreaMgrImpl(){
}

/**
* OperatorLog
*/
private OperatorLog log = null;
private int rowNum = 0;
/**
* OperatorLogSetter
*/
public void setLog(Object o) {
if (o instanceof OperatorLog) {
OperatorLog log = (OperatorLog) o;
this.log = log;
}
}

/**
* DataSource lookup jndi
*/
private String jndi = "jdbc/ccn";
private String tableName = "area";

/**
* log4j
*/
private static Logger logger= Logger.getLogger(AreaMgrImpl.class.getName());

/**
* 判断是否已经存在相同记录
* @param area 记录的值对象
* @return 是否存在另一记录与该记录相同
*/
public boolean existedArea( Area area ) {
//单引号替换
area = (Area)QuoteReplace.replace(area);

StringBuffer sqlBuf = new StringBuffer(100);
sqlBuf.append(" select count(*) from " + tableName);

/* @toDo: 要保留的行,去掉行前注释符,注:只保留主键(或联合主键的行)做是否存在的判断依据 */
sqlBuf.append(" where area_id = " + area.getAreaId()); //区域ID
// sqlBuf.append(" and area_name = '" + area.getAreaName()+ "'"); //区域名称
// sqlBuf.append(" and area_father_id = '" + area.getAreaFatherId()+ "'"); //所属区县
// sqlBuf.append(" and area_grandfather_id = '" + area.getAreaGrandfatherId()+ "'"); //所属省市

logger.warn("---sql:existedArea---" + sqlBuf);

CommonDAO dao = null;
ResultSet rs = null;
boolean existed = false;

try {
dao = new CommonDAO(jndi);
rs = dao.query(sqlBuf.toString());

if ( rs.next() ){
if (rs.getInt(1) != 0) {
existed = true;
}
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
dao.destroy();
}
return existed;
}

/**
* add a new record
* @param area 新增记录的值对象
* @return 是否添加成功
*/
public boolean addArea( Area area ){
//组合sql语句
StringBuffer sqlBuf = new StringBuffer(100);
sqlBuf
.append("insert into "+tableName)
.append("(")
.append("area_id") //区域ID
.append(",area_name") //区域名称
.append(",area_father_id") //所属区县
.append(",area_grandfather_id") //所属省市
.append(")")
.append(" values(");

StringBuffer sqlBufValues = new StringBuffer(100);
sqlBufValues
.append("" + area.getAreaId()) //区域ID
.append(",'" + area.getAreaName() + "'") //区域名称
.append(",'" + area.getAreaFatherId() + "'") //所属区县
.append(",'" + area.getAreaGrandfatherId() + "'") //所属省市
.append(")");

sqlBuf = sqlBuf.append(sqlBufValues);

logger.warn("---sql:addArea---"+sqlBuf);

//更新数据
return this.updateData( sqlBuf.toString(),"addArea" );
}

/**
* edit the specified object
* @param area 修改成的新记录的对象
* @return 修改是否成功
*/
public boolean editArea( Area area){
//组合sql语句
StringBuffer sqlBuf = new StringBuffer(100);
sqlBuf
.append("update "+tableName+" set ")
.append("area_id = " + area.getAreaId()) //区域ID
.append(",area_name = '" + area.getAreaName() + "'") //区域名称
.append(",area_father_id = '" + area.getAreaFatherId() + "'") //所属区县
.append(",area_grandfather_id = '" + area.getAreaGrandfatherId() + "'") //所属省市
.append(" where area_id = ")
.append(area.getAreaId());

logger.warn("---sql:editArea---"+sqlBuf);

//更新数据
return updateData( sqlBuf.toString(),"editArea" );
}

/**
* delete the specified object by id
* @param areaID 记录的ID值
* @return 删除记录是否成功
*/
private boolean delAreaById(String areaID) {
StringBuffer sqlBuf = new StringBuffer(100);
sqlBuf.append(" delete from "+tableName);
sqlBuf.append(" where area_id=");
sqlBuf.append(areaID);

logger.warn("---sql:delAreaById---"+sqlBuf);

boolean result = this.updateData( sqlBuf.toString(), "delAreaById" );
return result;
}

/**
* delete the specified objects
* @param areaIDs 多条记录ID组成的数组
* @return boolean 删除多条是否成功
*/
public boolean delAreas(String[] areaIDs) {
if ( areaIDs != null && areaIDs.length > 0 ) {
int size = areaIDs.length;
for (int i = 0; i < size; i++) {
if ( !this.delAreaById( areaIDs[i]) ) {
return false;
}
}
return true;
}
return false;
}

/**
* get the specified object
* @param areaId 记录的ID值
* @return 与该ID匹配的记录的值对象
*/
public Area getAreaByID( String areaId ){
Area area = null;

//组合查询条件
StringBuffer sqlBuf = new StringBuffer();
sqlBuf
.append("select * from "+tableName+" where area_id = ")
.append(areaId);

logger.warn("---sql:getAreaByID---"+sqlBuf);

CommonDAO dao = null;
ResultSet rs = null;

try{
dao = new CommonDAO(jndi);
rs = dao.query(sqlBuf.toString());

//读取结果集信息
if ( rs.next() ){
area = this.readDataFromRs(rs);
}

}catch( Exception ex ){
ex.printStackTrace();
}finally{
dao.destroy();
dao=null;
sqlBuf = null;
}
return area;
}

/**
* get all objects
* @param
* @return 全部记录的列表
*/
public ArrayList getAreaList(){
ArrayList arr = null;

//组合查询条件
String sql = "select * from "+tableName+" order by area_id desc";

logger.warn("---sql:getAreaList---"+sql);

CommonDAO dao = null;
ResultSet rs = null;

try{
dao = new CommonDAO(jndi);
rs = dao.query(sql);

//读取结果集信息
arr = this.readDataListFromRs(rs);
}catch( Exception ex ){
ex.printStackTrace();
}finally{
dao.destroy();
dao=null;
sql = null;
}
return arr;
}

/**
* get all objects
* @param area
* @return 满足查询条件的记录的对象组成的列表
*/
public ArrayList getAreaList(Area area ){
ArrayList arr = null;

//组合查询条件
StringBuffer sqlBuf = new StringBuffer(50);

sqlBuf.append( "select * from "+tableName);
sqlBuf.append( " where 1=1 ");
/* @todo: 可以在这里加上你自己的查询条件 */

sqlBuf.append( " order by area_id desc");

logger.warn("---sql:getAreaList---"+sqlBuf);

CommonDAO dao = null;
ResultSet rs = null;

try{
dao = new CommonDAO(jndi);
rs = dao.query(sqlBuf.toString());

//读取结果集信息
arr = this.readDataListFromRs(rs);
}catch( Exception ex ){
ex.printStackTrace();
}finally{
dao.destroy();
dao=null;
sqlBuf = null;
}
return arr;
}

/**
* get all objects by search
* 数值、日期等按指定区间查询
* @param areaSearch 查询条件的值对象
* @return 满足条件的记录组成的对象列表
*/
public ArrayList getAreaListBySearch(AreaSearch areaSearch ){
ArrayList arr = null;

StringBuffer sqlBuf = new StringBuffer(50);
StringBuffer sqlWhere = this.getSqlwherBySearch(areaSearch);
sqlBuf.append( "select * from " + tableName + " where 1=1 ");
sqlBuf.append(sqlWhere);
sqlBuf.append( " order by area_id desc");

logger.warn("---sql:getAreaListSplit---"+sqlBuf);

CommonDAO dao = null;
ResultSet rs = null;

try{
dao = new CommonDAO(jndi);
rs = dao.query(sqlBuf.toString());
//读取结果集信息
arr = this.readDataListFromRs(rs);
}catch( Exception ex ){
ex.printStackTrace();
}finally{
dao.destroy();
dao=null;
sqlBuf = null;
}
return arr;
}

/**
* 查询结果分页显示
* @param pageBean 页信息的对象
* @return 是否分页查询成功
*/
public boolean getAreaListSplit( Page pageBean ){
ArrayList arr = new ArrayList();
int pageSize = 0;
int pageNo = 0;
if (pageBean == null) {
return false;
}
if (pageBean.getPageSize() <= 0) {
pageBean.setPageSize(50);
}
if (pageBean.getPageNo()<= 0) {
pageBean.setPageNo(1);
}
pageSize = pageBean.getPageSize();
pageNo = pageBean.getPageNo();

StringBuffer sql = new StringBuffer(" select * from "+tableName+" order by area_id desc");
StringBuffer countSql = new StringBuffer("select count(*) from "+tableName);

logger.warn("---sql:getAreaListSplit---"+sql);
logger.warn("---countSql:getAreaListSplit---"+countSql);

CommonDAO dao = null;
try{
dao = new CommonDAO(jndi);
rowNum = PageDiv.getCount(countSql.toString(), dao);
pageBean.setPageInfo(rowNum, pageSize);
//执行查找
ResultSet rs = PageDiv.getResultSet(pageNo, pageSize, rowNum, sql.toString(), dao);
for (int i = 0; i < pageSize && rs.next(); i++) {
//从结果集中读取数据
arr.add(readDataFromRs(rs));
}
}catch( Exception ex ){
ex.printStackTrace();
}finally{
dao.destroy();
}
pageBean.setList(arr);
return true;
}

/**
* get objects by search ,display split
* 按值查询并分页显示,数值、日期等查指定区间
* @param pageBean 页信息对象
* @param areaSearch 查询条件对象
* @return 获得页列表是否成功
*/
public boolean getAreaListSplitBySearch( Page pageBean,AreaSearch areaSearch ){
ArrayList arr = new ArrayList();
int pageSize = 0;
int pageNo = 0;
if (pageBean == null) {
return false;
}
if (pageBean.getPageSize() <= 0) {
pageBean.setPageSize(15);
}
if (pageBean.getPageNo()<= 0) {
pageBean.setPageNo(1);
}
pageSize = pageBean.getPageSize();
pageNo = pageBean.getPageNo();

StringBuffer sqlWhere = this.getSqlwherBySearch(areaSearch);
StringBuffer sql = new StringBuffer(" select * from " + tableName + " where 1=1 " + sqlWhere + " order by area_id desc");
StringBuffer countSql = new StringBuffer("select count(*) from " + tableName + " where 1=1 " + sqlWhere);

logger.warn("---sql:getAreaListSplit---"+sql);
logger.warn("---countSql:getAreaListSplit---"+countSql);

CommonDAO dao = null;
try{
dao = new CommonDAO(jndi);
rowNum = PageDiv.getCount(countSql.toString(), dao);
pageBean.setPageInfo(rowNum, pageSize);
//执行查找
ResultSet rs = PageDiv.getResultSet(pageNo, pageSize, rowNum, sql.toString(), dao);
for (int i = 0; i < pageSize && rs.next(); i++) {
//从结果集中读取数据
arr.add(readDataFromRs(rs));
}
}catch( Exception ex ){
ex.printStackTrace();
}finally{
dao.destroy();
}
pageBean.setList(arr);
return true;
}

/**
* 读取值对象列表
* @param rs 结果集
* @return 从结果集中读取的对象列表
*/
private ArrayList readDataListFromRs(ResultSet rs) throws SQLException {
ArrayList arr = new ArrayList();
Area area = null;

try{
while (rs.next()) {
area = new Area();

//将字段值set到值对象中
area.setAreaId(rs.getString("area_id")); //区域ID
area.setAreaName(rs.getString("area_name")); //区域名称
area.setAreaFatherId(rs.getString("area_father_id")); //所属区县
area.setAreaGrandfatherId(rs.getString("area_grandfather_id")); //所属省市
arr.add(area);
}
}catch( Exception ex ){
ex.printStackTrace();
}
return arr;
}

/**
* 读取单个值对象
* @param rs 结果集
* @return 按某列读取的特定记录的值对象
*/
private Area readDataFromRs(ResultSet rs) throws SQLException {
Area area = new Area();
try{
//将字段值set到值对象中
area.setAreaId(rs.getString("area_id")); //区域ID
area.setAreaName(rs.getString("area_name")); //区域名称
area.setAreaFatherId(rs.getString("area_father_id")); //所属区县
area.setAreaGrandfatherId(rs.getString("area_grandfather_id")); //所属省市
}catch( Exception ex ){
ex.printStackTrace();
}
return area;
}

/**
* 更新数据 用于数据更新语句 Insert,Update,Delete
* @param updateSql 数据库更新语句
* @param logtype 数据库操作类型
* @return 更新成功与否
*/
private boolean updateData(String updateSql, String logtype) {
int returnInt = -1;
boolean returnFlag = false;
CommonDAO dao = null;

try {
dao = new CommonDAO("jdbc/ccn");
returnInt = dao.excute(updateSql);
if (returnInt != -1) {
returnFlag = true;
}
}
catch (Exception ex) {
ex.printStackTrace();
}
finally {
dao.destroy();
}

// 写入日志
if (log != null) {
log.setSql(updateSql);
log.setOperation(logtype);
OperatorLogger loggerUpdate = new OperatorLogger();
loggerUpdate.addLog(log);
}
return returnFlag;
}

/**
* 获得按值对象查询的查询条件
* @param areaSearch 条件查询的值对象
* @return sql查询条件
*/
private StringBuffer getSqlwherBySearch(AreaSearch areaSearch ){
areaSearch = (AreaSearch)QuoteReplace.replace(areaSearch); //值对象中的单引号替换

String areaId = areaSearch.getAreaId();
String areaName = areaSearch.getAreaName();
String areaFatherId = areaSearch.getAreaFatherId();
String areaGrandfatherId = areaSearch.getAreaGrandfatherId();
StringBuffer sqlWhere = new StringBuffer(" ");

if (areaId != null && areaId.trim().length() != 0) {
sqlWhere.append(" and area_id like '%").append(areaId).append("%' ");
}
if (areaName != null && areaName.trim().length() != 0) {
sqlWhere.append(" and area_name like '%").append(areaName).append("%' ");
}
if (areaFatherId != null && areaFatherId.trim().length() != 0) {
sqlWhere.append(" and area_father_id like '%").append(areaFatherId).append("%' ");
}
if (areaGrandfatherId != null && areaGrandfatherId.trim().length() != 0) {
sqlWhere.append(" and area_grandfather_id like '%").append(areaGrandfatherId).append("%' ");
}
return sqlWhere;
}
/**
* 根据不同类别得到区域名称
* @param areaSearch 条件查询的值对象,areaType 区域类别如:城市,区,县
* @return 符合条件的area集合
*/
public ArrayList getAreaInfo(AreaSearch areaSearch,String areaType){
ArrayList arr = null;

StringBuffer sqlBuf = new StringBuffer(50);
String areaId = areaSearch.getAreaId();
//得到省市名称
if(areaType.equals("sheng")){
sqlBuf.append("select * from area where area_grandfather_id = area_id and area_id =area_father_id ");
}
//得到市名称
if(areaId != null && areaType.equals("shi")){
sqlBuf.append("select * from area where area_grandfather_id = '"+areaId+"' and area_id=area_father_id and area_grandfather_id!=area_father_id");
}
//得到区县名称
if(areaId != null && areaType.equals("qu")){
sqlBuf.append("select * from area where area_father_id = '"+areaId+"' and area_id != area_father_id" );

}
sqlBuf.append( " order by area_id ");

logger.warn("---sql:getAreaListSplit---"+sqlBuf);
CommonDAO dao = null;
ResultSet rs = null;

try{
dao = new CommonDAO(jndi);
rs = dao.query(sqlBuf.toString());
//读取结果集信息
arr = this.readDataListFromRs(rs);
}catch( Exception ex ){
ex.printStackTrace();
}finally{
dao.destroy();
dao=null;
sqlBuf = null;
}
return arr;
}
}
何寻枋Nq
2008-10-13
知道答主
回答量:3
采纳率:0%
帮助的人:0
展开全部
1,先建一个bean,里面的变量,与数据库中的列相同:
public class PCourse {
/***
* *创建课业号,课程号,专业号,以及修改中用到的旧的课业号 的存储参数,
* 同时定义属性
*
*
*/
private String csID;
private String courseID;
private String speciaID;
private String oldcsID;

public String getcsID(){
return csID;
}
public void setcsID(String csID){
this.csID=csID;
}

public String getcourseID() {
return courseID;
}
public void setcourseID(String courseID) {
this.courseID = courseID;
}
public String getspeciaID() {
return speciaID;
}
public void setspeciaID(String speciaID) {
this.speciaID =speciaID;
}
public String getoldcsID() {
return oldcsID;
}
public void setoldcsID(String oldcsID) {
this.oldcsID =oldcsID;
}
}

2,然后建一个DAO(Database Access Object)接口,即里面就是一些数据库操作的方法,但先不实现他:

public interface PCourseDao {
/**定义在选课表上的插入方法
*
* @param pc
* @return
* @throws Exception
*/
public int insert(PCourse pc) throws Exception;
/**定义在选课表上的更新方法
*
* @param pc
* @return
* @throws Exception
*/
public int update(PCourse pc) throws Exception;
/**定义在选课表上的删除方法
*
* @param pc
* @return
* @throws Exception
*/
public int delete(String csID) throws Exception;
/**定义在选课表上的按课业号的查询方法
*
* @param pc
* @return
* @throws Exception
*/
public PCourse queryBycsID(String csID) throws Exception;
/**定义在选课表上的按课程号的查询方法
*
* @param pc
* @return
* @throws Exception
*/
public List queryBycourseId(String courseID) throws Exception;
/**定义在选课表上的按专业号查询方法
*
* @param spID
* @return
* @throws Exception
*/
public List queryByspID(String speciaID) throws Exception;
}

3,实现接口类:

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import com.hb.sim.vo.Attendance;
import com.hb.sim.vo.PCourse;
import com.hb.sim.dao.PCourseDao;
import com.hb.sim.db.DbConnection;

public class PCourseDaoImpl implements PCourseDao{
public int updateLines;
public PCourse pc=null;
private DbConnection db=null;
public PCourseDaoImpl(){
db=new DbConnection();
}

public int insert(PCourse pc) throws Exception {

String sql="insert into P_COURSE (CS_ID,SPECIA_ID,COURSE_ID) values (?,?,?)";
Connection conn=db.getConnection();
PreparedStatement pstmt=null;
try {
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,pc.getcsID());
pstmt.setString(2, pc.getspeciaID());
pstmt.setString(3, pc.getcourseID());
updateLines=pstmt.executeUpdate();

} catch (SQLException e) {
e.printStackTrace();
}
finally{
db.close();
}
return updateLines;

}

public int delete(String csID) throws Exception {
String sql="delete from P_COURSE where CS_ID=?";
Connection conn=db.getConnection();
PreparedStatement pstmt=null;
try {
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,csID);
updateLines=pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}
finally{
try {
if(pstmt!=null){
pstmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}

db.close();
return updateLines;

}
public int update(PCourse pc) throws Exception {
String sql="update P_COURSE set SPECIA_ID=?,COURSE_ID=? where CS_ID=?";
Connection conn=db.getConnection();
PreparedStatement pstmt=null;
try {
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, pc.getspeciaID());
pstmt.setString(2, pc.getcourseID());
pstmt.setString(3, pc.getcsID());
updateLines=pstmt.executeUpdate();

} catch (SQLException e) {
e.printStackTrace();
}
finally{
try {
if(pstmt!=null){
pstmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}

db.close();
return updateLines;
}

public List queryBycourseId(String courseID) throws Exception{
List l=new ArrayList();
String sql="select * from P_COURSE where COURSE_ID=?";
Connection conn=db.getConnection();
PreparedStatement pstmt=null;
try {
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, courseID);
ResultSet rs=pstmt.executeQuery();
while(rs.next()){
PCourse pc=new PCourse();
pc.setcsID(rs.getString("CS_ID"));
pc.setcourseID(rs.getString("COURSE_ID"));
pc.setspeciaID(rs.getString("SPECIA_ID"));
l.add(pc);
}

rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
finally{
try {
if(pstmt!=null){
pstmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}

db.close();
return l;
}
public List queryByspID(String speciaID) {

List l=new ArrayList();
String sql="select * from P_COURSE where SPECIA_ID=?";
Connection conn=db.getConnection();
PreparedStatement pstmt=null;
try {

pstmt=conn.prepareStatement(sql);
pstmt.setString(1, speciaID);
ResultSet rs=pstmt.executeQuery();
while(rs.next()){
PCourse pc=new PCourse();
pc.setcsID(rs.getString("CS_ID"));
pc.setspeciaID(rs.getString("SPECIA_ID"));
pc.setcourseID(rs.getString("COURSE_ID"));
l.add(pc);

}

rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
finally{
try {
if(pstmt!=null){
pstmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}

db.close();
return l;
}

public PCourse queryBycsID(String csID) throws Exception {
String sql="select * from P_COURSE where CS_ID=?";
Connection conn=db.getConnection();
PreparedStatement pstmt=null;
PCourse pc=null;
try {
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,csID);
ResultSet rs=pstmt.executeQuery();
while(rs.next()){
pc=new PCourse();
pc.setcsID(rs.getString("CS_ID"));
pc.setcourseID(rs.getString("COURSE_ID"));
pc.setspeciaID(rs.getString("SPECIA_ID"));
}
rs.close();
}catch (SQLException e) {
e.printStackTrace();
}
finally{
try {
if(pstmt!=null){
pstmt.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}

db.close();
return pc ;
}

}

4,就是你的逻辑代码,set你的存储对象,然后调用相应的数据库操作方法,就会保存到数据库中

按你的要求,大概就是这样,有什么疑问给我留言!!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
304009100
2008-10-12 · TA获得超过128个赞
知道小有建树答主
回答量:125
采纳率:0%
帮助的人:121万
展开全部
不知道怎么引用bean?
javabean也是一个普通的类啊,要是和你用来调用bean在同一包中就不用写import语句了,直接实例化它啊,比如你的bean的名字叫UserInfo
你就在类中写
UserInfo ui=new UserInfo();
然后就可以读取bean里面的数据了,不要告诉我你bean没写规范
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式