JAVA中对存储过程的调用方法(五) 查询数据的存储过程(模糊查询)
时间:2011-07-03 本站整理
五、查询数据的存储过程(模糊查询)
-----------------存储过程---------------------
create procedure FindCusts
@cust varchar(10)
as
select customerid from orders where customerid
like ''%''+@cust+''%''
---------------执行---------------------------
execute FindCusts ''alfki''
-------------在JAVA中调用--------------------------
import java.sql.*;
public class ProcedureTest
{
public static void main(String args[]) throws Exception
{
//加载驱动
DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
//获得连接
Connection conn=DriverManager.getConnection("jdbc:odbc:mydata","sa","");
//创建存储过程的对象
CallableStatement c=conn.divpareCall("{call FindCusts(?)}");
c.setString(1,"Tom");
ResultSet rs=c.executeQuery();
while(rs.next())
{
String cust=rs.getString("customerid");
System.out.println (cust);
}
c.close();
}
}
|