2013年7月26日星期五

JAVA call stored procedures

There are something like SQL2000 stored procedures, JAVA in how to properly call

CREATE proc GetFixFlow
(@ BarCode varchar (30))
as
create table # FixFLow
(
fDate datetime null,
flag varchar (20) null,
fNO varchar (20) null,
fman varchar (20) null,
fdep varchar (100) null
)

insert into # FixFLow (fDate, flag, fNO, fman, fdep)
select F_Date, 'storage', Fix_Batch.F_Number, p1.P_Name, 'procurement:' + p2.P_Name + '.' + 'unit:' + F_Factory + '. '+' warehouse: '+ S_Name
from Fix_Batch left join Fix_Product on Fix_Batch.F_Number = Fix_Product.F_Number
left join Storeroom_Set on Fix_Product.S_Number = Storeroom_Set.S_Number
left join Person_Set p1 on F_StorageMan = p1.P_Number
left join Person_Set p2 on Fix_Batch.F_BuyMan = p2.P_Number
where F_CodeBar = @ BarCode

insert into # FixFLow (fDate, flag, fNO, fman)
select F_RejectDate, 'scrap', FR_Number, P_Name
from Fix_Reject, Person_Set where
Fix_Reject.F_RejectMan = Person_Set.P_Number and F_CodeBar = @ BarCode

select # FixFLow.fDate, # FixFLow.flag, # FixFLow.fNO, # FixFLow.fman, # FixFLow.fdep from # FixFLow order by fDate

GO
----------------------------------

DriverManager.registerDriver (new sun.jdbc.odbc.JdbcOdbcDriver ());
/ / get the link
Connection conn = DriverManager.getConnection ("jdbc: odbc: gdzc", "sa", "");
/ / create the stored procedure object
CallableStatement c = conn.prepareCall ("call GetFixFlow");

ResultSet rs = c.executeQuery ();

while (rs.next ()) {

Date fDate = rs.getDate ("fDate");
String flag = rs.getString ("flag");
String fNO = rs.getString ("fNO");
String fman = rs.getString ("flag");
String fdep = rs.getString ("fdep");

}
c.close ();
---------------------- this call does the problem lie?
------ Solution ---------------------------------------- ----
The above is an example, no parameters, the direct "call the stored procedure name," What is your problem?
------ For reference only -------------------------------------- -
call the stored procedure name (parameter list), specific your question?
------ For reference only -------------------------------------- -


ResultSet rs = c.executeQuery (); implementation of this step will be directly explode when
pass in this parameter does not need it
------ For reference only --------------------------- ------------


solve Ha Thank you still need to pass a parameter into the!

没有评论:

发表评论