JAVA中对存储过程的调用方法(五)查询数据的存储过程(模糊查询)

五、查询数据的存储过程(模糊查询)

-----------------存储过程---------------------create procedure FindCusts@cust varchar(10)asselect 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();}}

妩媚动人,让我感受到了大自然的神奇。

JAVA中对存储过程的调用方法(五)查询数据的存储过程(模糊查询)

相关文章:

你感兴趣的文章:

标签云: