create procedure findStudentByLike
@studentLike varchar(50)
as
select * from studentInformation where studentNumber like '%'+@studentLike+'%' or studentName like '%'+@studentLike+'%'
go
execute findStudentByLike '郭'
关键是上面的那条sql语句可能有问题,尽管直接在数据库查询分析器里面执行,是可以返回结果集的。但是在java代码中调用就不能返回结果集。
public Vector getStudentInformationByLike(String seemLike)
{
DbConnection connection=new DbConnection();
conn=connection.getConnection();
try {
stmt=conn.prepareCall("{call findStudentByLike(?)}");
stmt.setString(1,seemLike);
rs=stmt.executeQuery();
ResultSetMetaData rsmd=rs.getMetaData();
int columns=rsmd.getColumnCount();
v=new Vector();
while(rs.next())
{
Vector ve=new Vector();
for(int i=1;i<=columns;i++)
{
if(i<=2)
{
ve.add(rs.getString(i).trim());
}
else
{
ve.add(rs.getObject(i));
}
}
v.add(ve);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
close();
return v;
}