我想将 base64 图像保存到我的 SQL Server 2008 R2,我使用了这个:
Connection con = Database.getConnection();
CallableStatement callableStatement = null;
try
{
callableStatement = con.prepareCall("{call insertRestaurantFoodImage2(?,?)}");
callableStatement.setInt(1, ID);
callableStatement.setString(2, stringImage);
callableStatement.executeUpdate();
}
catch (SQLException e)
{
e.printStackTrace();
}
保存字符串的存储过程是:
ALTER PROCEDURE dbo.insertRestaurantFoodImage2
(@restaurantFoodID INT,
@image VARCHAR(MAX))
AS
BEGIN
SET NOCOUNT ON
UPDATE Food_Restaurant
SET [image] = @image
WHERE ID = @restaurantFoodID
END
像这样检索数据:
Connection con = Database.getConnection();
CallableStatement callableStatement = null;
try
{
callableStatement = con.prepareCall("{call getRestaurantFoodImage2(?,?)}");
callableStatement.setInt(1, getID());
callableStatement.registerOutParameter(2, java.sql.Types.VARCHAR);
callableStatement.execute();
image = callableStatement.getString(2);
}
catch (SQLException e)
{
e.printStackTrace();
}
获取图像的存储过程是:
ALTER PROCEDURE dbo.insertRestaurantFoodImage2
(@restaurantFoodID INT,
@image VARCHAR(MAX))
AS
BEGIN
SET NOCOUNT ON
UPDATE Food_Restaurant
SET [image] = @image
WHERE ID = @restaurantFoodID
END
当我在插入字符串之前和检索字符串之前检查字符串时,结果不相等,检索到的图像大约有前 500 个(更少或更多)字符。
请问我做错了什么?
我知道你会告诉我,尝试使用 varbinary 而不是 varchar,所以请看这个问题,我尝试了编码和解码 base64 excpetion 存储到 sql server 2008 r2的问题
请帮忙