om5
unread,Apr 6, 2011, 6:52:04 PM4/6/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mybatis-user
I have searched the forum but have not been able to figure out this
particular problem. The error is as follows. Your help is appreciated.
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause:
com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near
'@P0'.
### The error may involve
org.mybatis.guice.sample.mapper.UserMapper.insertUser-Inline
### The error occurred while setting parameters
### Cause: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect
syntax near '@P0'.
at
org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:
8)
at
org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:
120)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.ibatis.session.SqlSessionManager
$SqlSessionInterceptor.invoke(SqlSessionManager.java:253)
at $Proxy42.update(Unknown Source)
at
org.apache.ibatis.session.SqlSessionManager.update(SqlSessionManager.java:
187)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:
59)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:38)
at $Proxy43.insertUser(Unknown Source)
at
org.mybatis.guice.sample.service.FooServiceMapperImpl.insertUser(FooServiceMapperImpl.java:
60)
Environment: myBatis 3.0.4 and SQL Server 2008
Mapper:
<update id="insertUser"
parameterType="org.mybatis.guice.sample.domain.User"
statementType="CALLABLE">
call insert_user (#{id,mode=IN,jdbcType=VARCHAR},
#{name,mode=IN,jdbcType=VARCHAR})
</update>
Stored Procedure:
CREATE PROCEDURE insert_user @id varchar(80), @name varchar(80)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT users (id, name) VALUES (@id, @name)
END
GO
UserMapper.java:
public interface UserMapper {
User getUser(String userId);
void updateUser(User user);
void insertUser(User user);
}
FooServiceImpl.java
public User insertUser(User user)
{
this.userMapper.insertUser(user);
return user;
}