This Domain(Admin5.com) is for Sale:

在SQLServer中使用数据库存储过程的代码

时间:2007-12-23  来源:不详  作者:迈克DB


先在SQL Server中创建存储过程如下:
CREATE PROCEDURE InsertOrtho
(@ChildID varchar(10) out,
@date datetime out,
@therapistID varchar(10) out,
@clinicID integer out,
@skeletal varchar(1) out,
@angleClass varchar(1) out,
@deflection varchar(1) out,
@OrthoNotes varchar(200) out)
AS
BEGIN
INSERT INTO tblPatientOrtho VALUES
(@ChildID, @date, @TherapistID, @ClinicID, @Skeletal, @angleClass, @deflection, @OrthoNotes)
RETURN
END 这是一个向数据库插入的存储过程,所有的参数都是输出的,在JAVA里可以这样调用这个存储过程,程序如下:
前面数据库的连接我就不写了
public boolean InsertOrtho(Ortho ortho, String childID)
{
boolean success = true; try
{
CallableStatement stmt = con.prepareCall("{call InsertOrtho(?, ?, ?, ?, ?, ?, ?, ?)}");
stmt.registerOutParameter(1, java.sql.Types.VARCHAR); 本文来自织梦
stmt.registerOutParameter(2, java.sql.Types.TIMESTAMP);
stmt.registerOutParameter(3, java.sql.Types.VARCHAR);
stmt.registerOutParameter(4, java.sql.Types.INTEGER);
stmt.registerOutParameter(5, java.sql.Types.VARCHAR);
stmt.registerOutParameter(6, java.sql.Types.VARCHAR);
stmt.registerOutParameter(7, java.sql.Types.VARCHAR);
stmt.registerOutParameter(8, java.sql.Types.VARCHAR); stmt.setString(1, childID);
stmt.setObject(2, ortho.GetDate());
stmt.setString(3, ortho.GetTherapistID());
stmt.setInt(4, ortho.GetClinicID());
stmt.setString(5, ortho.GetSkeletal());
stmt.setString(6, ortho.GetAngleClass());
stmt.setString(7, ortho.GetDeflection());
stmt.setString(8, ortho.GetOrthoNotes());
stmt.executeUpdate();
copyright dedecms

stmt.clearParameters();
stmt.close();
}
catch (SQLException e)
{
database.AddSQLError(e, "InsertOrtho()");
e.printStackTrace();
success = false;
}
catch (java.lang.Exception e)
{
database.AddException(e, "InsertOrtho()");
e.printStackTrace();
success = false;
}
return success;
}
希望对大家的数据库开发有所帮助   asp">存储过程asp?tags=数据库">数据库

看完这篇,您有何感觉呢?

文章评论

共有位Admini5网友发表了评论 查看完整内容

24小时热门信息