我现在用的 dao 模式有两张表 一张是 卡号表,另一张是订购表
我需要实现的功能是在订购的同时,也就是往订购表里面插入数据的时候,从卡表里面读取卡号然后和订购表一起往里面插入数据!这个功能我实现不了啊! 不知道怎么能从卡表里面读取出来,然后再插入另一张表里去??
哪位高手能帮帮我啊 !!
十分火急
代码如下:
dao:
/**
* 从卡库中查询所有的卡号
* @return
* @throws DaoException
*/
List<Tcard> getListTcard()throws DaoException;
dao 操作的实现类:
//查询卡表中的卡号!
public List<Tcard> getListTcard() throws DaoException { QueryRunner qr = new QueryRunner(); List<Tcard> list = new ArrayList<Tcard>();
Connection conn = ConnectionFactory.getConnection();
String sql = "select * from t_card where status = 1";
try {
list = qr.query(conn, sql, new BeanListHandler<Tcard>(Tcard.class));
} catch (SQLException e) {
e.printStackTrace();
throw new DaoException("查询所有部门列表时异常", e);
}
return list;
} //往订单表里面插入数据 QueryRunner qr = new QueryRunner();
Connection conn = ConnectionFactory.getConnection(); boolean validorderid = true;
int n = 0;
while (!validorderid) {
n++;
if (n > 20)
break;
String oid = car.MakeOrderID();
String SqlStr = "select * from t_cardorder where oid='" + oid + "'"; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(SqlStr);
if (!rs.next())
validorderid = true;
}
String sql = "insert into t_cardorder (cardid,oid,productid,ppackage,dname,dphone,daddress,dtime,edid,tname,tphone,taddress,ttime,status)values('"
+ (r.nextInt()) + "','" + temp + "',?,?,?,?,?,?,?,?,?,?,?,1)"; Object[] params = { tcardor.getProductid(), tcardor.getPpackage(),
tcardor.getDname(), tcardor.getDphone(), tcardor.getDaddress(),
tcardor.getDtime(), tcardor.getEdid(), tcardor.getTname(),
tcardor.getTphone(), tcardor.getTaddress(), tcardor.getTtime() };
try {
qr.update(conn, sql, params);
} catch (SQLException e) {
throw new DaoException("新增时出现异常", e);
} r.nextInt()) 我现在用的是随机数! 其实是往里面插入从卡表里面读取出来的卡号!
我需要实现的功能是在订购的同时,也就是往订购表里面插入数据的时候,从卡表里面读取卡号然后和订购表一起往里面插入数据!这个功能我实现不了啊! 不知道怎么能从卡表里面读取出来,然后再插入另一张表里去??
哪位高手能帮帮我啊 !!
十分火急
代码如下:
dao:
/**
* 从卡库中查询所有的卡号
* @return
* @throws DaoException
*/
List<Tcard> getListTcard()throws DaoException;
dao 操作的实现类:
//查询卡表中的卡号!
public List<Tcard> getListTcard() throws DaoException { QueryRunner qr = new QueryRunner(); List<Tcard> list = new ArrayList<Tcard>();
Connection conn = ConnectionFactory.getConnection();
String sql = "select * from t_card where status = 1";
try {
list = qr.query(conn, sql, new BeanListHandler<Tcard>(Tcard.class));
} catch (SQLException e) {
e.printStackTrace();
throw new DaoException("查询所有部门列表时异常", e);
}
return list;
} //往订单表里面插入数据 QueryRunner qr = new QueryRunner();
Connection conn = ConnectionFactory.getConnection(); boolean validorderid = true;
int n = 0;
while (!validorderid) {
n++;
if (n > 20)
break;
String oid = car.MakeOrderID();
String SqlStr = "select * from t_cardorder where oid='" + oid + "'"; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(SqlStr);
if (!rs.next())
validorderid = true;
}
String sql = "insert into t_cardorder (cardid,oid,productid,ppackage,dname,dphone,daddress,dtime,edid,tname,tphone,taddress,ttime,status)values('"
+ (r.nextInt()) + "','" + temp + "',?,?,?,?,?,?,?,?,?,?,?,1)"; Object[] params = { tcardor.getProductid(), tcardor.getPpackage(),
tcardor.getDname(), tcardor.getDphone(), tcardor.getDaddress(),
tcardor.getDtime(), tcardor.getEdid(), tcardor.getTname(),
tcardor.getTphone(), tcardor.getTaddress(), tcardor.getTtime() };
try {
qr.update(conn, sql, params);
} catch (SQLException e) {
throw new DaoException("新增时出现异常", e);
} r.nextInt()) 我现在用的是随机数! 其实是往里面插入从卡表里面读取出来的卡号!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货