'Mybatis escape period character in mapper
I am a total zero in tomcat/spring web development, I am a mobile developer but I have been asked for change dbname in a spring project. From "SOME_NAME" to "SomeName.Database" pattern Initial file:
public interface StatDao {
@Options(statementType = StatementType.CALLABLE)
@Select("{call SOME_NAME.dbo.GetResults(#{sex, mode=IN}, #{age, mode=IN}, #{maritalStatus, mode=IN}, #{childrensCount, mode=IN}, " +
"#{addressType, mode=IN}, #{regionId, mode=IN}, #{districtId, mode=IN}, #{socialStatus, mode=IN}, #{pollId, mode=IN}, " +
"#{questionId, mode=IN})}")
@Results(value = {
@Result(column = "p_id", property = "pollId"),
@Result(column = "question_id", property = "questionId"),
@Result(column = "answer_id", property = "answerId"),
@Result(column = "count_users", property = "countUsers"),
@Result(column = "percent_users", property = "percentUsers")
})
public List<Slice> statistic(Request params);
What I changed:
public interface StatDao {
@Options(statementType = StatementType.CALLABLE)
@Select("{call SomeName.Database.dbo.GetResults(#{sex, mode=IN}, #{age, mode=IN}, #{maritalStatus, mode=IN}, #{childrensCount, mode=IN}, " +
"#{addressType, mode=IN}, #{regionId, mode=IN}, #{districtId, mode=IN}, #{socialStatus, mode=IN}, #{pollId, mode=IN}, " +
"#{questionId, mode=IN})}")
@Results(value = {
@Result(column = "p_id", property = "pollId"),
@Result(column = "question_id", property = "questionId"),
@Result(column = "answer_id", property = "answerId"),
@Result(column = "count_users", property = "countUsers"),
@Result(column = "percent_users", property = "percentUsers")
})
public List<Slice> statistic(Request params);
But now I have an exception like this
Failed to fetch result from remote service org.springframework.jdbc.UncategorizedSQLException:
Error querying database. Cause: com.microsoft.sqlserver.jdbc.SQLServerException: Could not find server 'SomeName' in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers
I think that mybatis thinks that SomeName is a name of server but "SomeName.Database" supposed to be a name of a database without a server name. I failed to escape period character in a name of database, I tried something like this SomeName.Database, SomeName.Database, ${SomeName.Database} but it doesn't work at all. How to force mybatis SomeName.Database is a name of database, but not ServerName?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
