首页 新闻 会员 周边

MyBatis传入两个参数查询,报错说是sql语句错误

0
[待解决问题]
 1 ### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '}' at line 6
 2 ### The error may exist in file [D:\workspace\eclipse\Contact\target\classes\com\cmbc\mapper\ContactMapper.xml]
 3 ### The error may involve com.cmbc.dao.ContactMapper.queryByNamePassword-Inline
 4 ### The error occurred while setting parameters
 5 ### SQL: select       id, name, password, sex, birthday, address      from contact   where name = ? and password= ?}
 6 ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '}' at line 6
 7 ]
 8 [org.mybatis.spring.SqlSessionUtils]Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@143aaff8]
 9 [org.springframework.jdbc.datasource.DataSourceUtils]Returning JDBC Connection to DataSource
10 [org.springframework.test.context.support.DirtiesContextTestExecutionListener]After test method: context [[TestContext@5d1f72db testClass = TestContactMapper, testInstance = com.cmbc.test.TestContactMapper@3badb7a0, testMethod = testQueryByNamePassoword@TestContactMapper, testException = org.springframework.jdbc.BadSqlGrammarException: 
11 ### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '}' at line 6
12 ### The error may exist in file [D:\workspace\eclipse\Contact\target\classes\com\cmbc\mapper\ContactMapper.xml]
13 ### The error may involve com.cmbc.dao.ContactMapper.queryByNamePassword-Inline
14 ### The error occurred while setting parameters
15 ### SQL: select       id, name, password, sex, birthday, address      from contact   where name = ? and password= ?}
16 ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '}' at line 6
17 ; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '}' at line 6, mergedContextConfiguration = [MergedContextConfiguration@b7e2544 testClass = TestContactMapper, locations = '{classpath:spring.xml, classpath:spring-mybatis.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader']]], class dirties context [false], class mode [null], method dirties context [false].
18 [org.springframework.test.context.web.ServletTestExecutionListener]Resetting RequestContextHolder for test context [TestContext@5d1f72db testClass = TestContactMapper, testInstance = com.cmbc.test.TestContactMapper@3badb7a0, testMethod = testQueryByNamePassoword@TestContactMapper, testException = org.springframework.jdbc.BadSqlGrammarException: 
19 ### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '}' at line 6
20 ### The error may exist in file [D:\workspace\eclipse\Contact\target\classes\com\cmbc\mapper\ContactMapper.xml]
21 ### The error may involve com.cmbc.dao.ContactMapper.queryByNamePassword-Inline
22 ### The error occurred while setting parameters
23 ### SQL: select       id, name, password, sex, birthday, address      from contact   where name = ? and password= ?}
24 ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '}' at line 6

 

<select id="queryByNamePassword" resultMap="BaseResultMap"
        parameterType="java.lang.String">
        select
        <include refid="Base_Column_List" />
        from contact
        where name = #{0} and password= #{1}}
</select>
Contact queryByNamePassword(String name, String password);

 

远歌的主页 远歌 | 菜鸟二级 | 园豆:210
提问于:2016-05-12 11:33
< >
分享
所有回答(1)
0

xml 里面多了个}

胖胖的半山兄 | 园豆:240 (菜鸟二级) | 2016-05-12 19:02

谢谢你,我前面已经找到了。因为最近比较忙所以就没有上来博客园看。你说的没有错,xml里面多了个大括号

支持(0) 反对(0) 远歌 | 园豆:210 (菜鸟二级) | 2016-05-14 21:56

@远歌: 嗯嗯,找到了就好

支持(0) 反对(0) 胖胖的半山兄 | 园豆:240 (菜鸟二级) | 2016-05-14 21:56

@胖胖的半山兄: 以后不懂的还希望多多指教

支持(0) 反对(0) 远歌 | 园豆:210 (菜鸟二级) | 2016-05-14 21:57

@远歌: 相互学习吧~

支持(0) 反对(0) 胖胖的半山兄 | 园豆:240 (菜鸟二级) | 2016-05-14 22:01
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册