I want to save base64 image to my sql server 2008 r2, i used this:
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();
}
the stored procedure to save the string is :
ALTER PROCEDURE dbo.insertRestaurantFoodImage2
(
@restaurantFoodID INT,
@image VARCHAR(MAX)
)
AS
BEGIN
SET NOCOUNT ON
UPDATE Food_Restaurant
SET [image] = @image
WHERE ID = @restaurantFoodID
END
retrive data like this:
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();
}
the stored procedure to get image is :
ALTER PROCEDURE dbo.insertRestaurantFoodImage2
(
@restaurantFoodID INT,
@image VARCHAR(MAX)
)
AS
BEGIN
SET NOCOUNT ON
UPDATE Food_Restaurant
SET [image] = @image
WHERE ID = @restaurantFoodID
END
when i check the string before insert it and after retirve it , the result was n't equaled, the retirve image has about the first 500 (less or more) chars, what am i doing wrong please.
I know u will tell me, try to use varbinary instead of varchar, so please look at this question, i tried and had problems encode and decode base64 excpetion storing to sql server 2008 r2
please help , please help