int workserial,int Id,int roomId //几个变量
sql = "select dutyman from taw_rm_assign_sub where workserial = ?";
sql ="select b.id from taw_rm_assignwork a,taw_rm_assignwork b where a.room_id = b.room_id and a.room_id = ? and workserial = ? and a.starttime_defined = b.endtime_defined and a.id = ? ";
sql = "select dutyman from taw_rm_record where id = "+b.id+"";
sql = "update taw_rm_record set dutyman = "+rs.getString(Dutyman)+" where id = ?";//应用的sql
sql = "update taw_rm_record set hander = B where id = ?";
sql = "update taw_rm_record set receiver = A where id ="+b.id+"";
//最后提交
sql = "select dutyman from taw_rm_assign_sub where workserial = ?";
sql ="select b.id from taw_rm_assignwork a,taw_rm_assignwork b where a.room_id = b.room_id and a.room_id = ? and workserial = ? and a.starttime_defined = b.endtime_defined and a.id = ? ";
sql = "select dutyman from taw_rm_record where id = "+b.id+"";
sql = "update taw_rm_record set dutyman = "+rs.getString(Dutyman)+" where id = ?";//应用的sql
sql = "update taw_rm_record set hander = B where id = ?";
sql = "update taw_rm_record set receiver = A where id ="+b.id+"";
//最后提交
PreparedStatement pstmt = conn.prepareStatement(sql);
然后对 sql 里面的 ?进行赋值。如 a,b就是代表具体的数值
pstmt.setInt(1, a);
pstmt.setString(2,b);
.......最后 pstmt.executeQuery(); // 查询用
pstmt.executeUpdate(); //更新 删除,插入用最后conn.commit();
Connection con=null;
Statement pstm=null;
int[] k=null;
boolean bool_return=true;
try{
con=dbm.getConnection("sqlserver");
// con.setAutoCommit(false);
pstm = con.createStatement();
for(int j=0;j<sqls.length;j++){
pstm.addBatch(sqls[j]); }
k= pstm.executeBatch();
pstm.close();
}
catch(Exception ex){
System.out.println("调用insertsComm时:"+ex.toString());
bool_return=false;
}
finally{
if(con!=null)dbm.freeConnection("sqlserver",con);
}
return bool_return;
}
cstmt = DBConn.prepareCall("{call USP_getPopedom('" + Parent + "')}",java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
ResultSet RS = cstmt.executeQuery();
while(RS.next() && !RS.isAfterLast())
{
.....................
}
..................................................
这是一般的select返回数据。
多个的话可以用CallableStatement返回多个结果集
..................................................
Comm = DBConn.prepareCall(strSQL);
Comm.execute(); //1
RS = Comm.getResultSet();
while(RS.next())
{
.............
}
RS.close(); //2
if (Comm.getMoreResults()) ///////用getMoreResults()
RS = Comm.getResultSet();
while(RS.next())
{
........
}
RS.close();.................................Comm.close();
DBConn.close();
CREATE procedure GetSaleCu
@PeD varchar(20)
as
begin select CustomerName
,isnull(salecustomerdaily.forecasemoney,'') as forecasemoney
,isnull(salecustomerdaily.serverperiod,'') as serverperiod
,isnull(salecustomerdaily.ForecaseTractDate,'') as ForecaseTractDate
,isnull(salecustomerdaily.UpdateDate,'') as UpdateDate
from salecustomerdaily
where salecustomerdaily.PersonID=@PeD
select lastlinkcontent
,basedictionary.name as CusStateName
,convert(varchar(3)
,isnull(salecustomerdaily.forecasemoney,'') as forecasemoney
from salecustomer
where salecustomer.PersonID=@PeD end
GO