先在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 suclearcase/" target="_blank" >ccess = 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;
}
希望对大家的数据库开发有所帮助