WEB开发网
开发学院数据库MSSQL Server 实用的存储过程之二 阅读

实用的存储过程之二

 2007-11-11 10:02:35 来源:WEB开发网   
核心提示: 先在sql server(WINDOWS平台上强大的数据库平台)中创建存储过程如下: CREATE PROCEDURE InsertOrtho (@ChildID varchar(10) out, @date datetime out, @therapistID varchar(1


   
先在sql server(WINDOWS平台上强大的数据库平台)中创建存储过程如下:
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();
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;
}

希望对大家的数据库开发有所帮助

上一页  1 2 3 4 

Tags:实用 存储 过程

编辑录入:coldstar [复制链接] [打 印]
赞助商链接