跟着课程敲得报错了,唉
F:\Ajava\JDK\jdk1.8.0_221\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:F:\A-IDEA\IntelliJ IDEA 2019.3.3\lib\idea_rt.jar=59998:F:\A-IDEA\IntelliJ IDEA 2019.3.3\bin" -Dfile.encoding=UTF-8 -classpath "F:\A-IDEA\IntelliJ IDEA 2019.3.3\lib\idea_rt.jar;F:\A-IDEA\IntelliJ IDEA 2019.3.3\plugins\junit\lib\junit5-rt.jar;F:\A-IDEA\IntelliJ IDEA 2019.3.3\plugins\junit\lib\junit-rt.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\charsets.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\deploy.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\ext\access-bridge-64.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\ext\cldrdata.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\ext\dnsns.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\ext\jaccess.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\ext\jfxrt.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\ext\localedata.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\ext\nashorn.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\ext\sunec.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\ext\sunjce_provider.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\ext\sunmscapi.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\ext\sunpkcs11.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\ext\zipfs.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\javaws.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\jce.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\jfr.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\jfxswt.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\jsse.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\management-agent.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\plugin.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\resources.jar;F:\Ajava\JDK\jdk1.8.0_221\jre\lib\rt.jar;F:\A-IDEA\workspace\mybatis\target\test-classes;F:\A-IDEA\workspace\mybatis\target\classes;F:\Atomcat\maven-repo\org\mybatis\mybatis\3.5.1\mybatis-3.5.1.jar;F:\Atomcat\maven-repo\mysql\mysql-connector-java\5.1.47\mysql-connector-java-5.1.47.jar;F:\Atomcat\maven-repo\junit\junit\4.12\junit-4.12.jar;F:\Atomcat\maven-repo\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 com.imooc.mybatis.MyBatisTestor,testSelectByPriceRange Sun Feb 23 15:03:03 CST 2020 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. org.apache.ibatis.exceptions.PersistenceException: ### 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 'null' at line 5 ### The error may exist in mappers/goods.xml ### The error may involve goods.selectByPriceRange-Inline ### The error occurred while setting parameters ### SQL: select * from t_goods where current_price between ? and ? order by current_price limit 0,? ### 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 'null' at line 5 at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:135) at com.imooc.mybatis.MyBatisTestor.testSelectByPriceRange(MyBatisTestor.java:83) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58) Caused by: 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 'null' at line 5 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at com.mysql.jdbc.Util.getInstance(Util.java:408) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3978) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3914) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2495) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1903) at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1242) at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64) at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) ... 25 more Process finished with exit code -1
19
收起
正在回答 回答被采纳积分+1
4回答
dobe001
2020-02-23 15:35:08
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="goods"> <select id="selectByPriceRange" parameterType="java.util.Map" resultType="com.imooc.mybatis.entity.Goods"> select * from t_goods where current_price between #{min} and #{max} order by current_price limit 0,#{limit} </select> </mapper>
dobe001
2020-02-23 15:34:17
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <settings> <!-- goods_id ==> goodsId 驼峰命名转换--> <setting name="mapUnderscoreToCamelCase" value="true"/> </settings> <environments default="dev"> <environment id="dev"> <transactionManager type="JDBC"/> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/babytun?useUnicode=true&characterEncoding=UTF-8"/> <property name="username" value="root"/> <property name="password" value="ccc980916"/> </dataSource> </environment> </environments> <mappers> <mapper resource="mappers/goods.xml"/> </mappers> </configuration>
dobe001
2020-02-23 15:33:45
public void testSelectByPriceRange() throws Exception{
SqlSession session = null;
try {
session = MyBatisUtils.openSession();
Map param = new HashMap();
param.put("min", 100);
param.put("max",500);
param.put("limit",10);
List<Goods> list = session.selectList("goods.selectByPriceRange");
for (Goods g : list) {
System.out.println(g.getTitle()+":"+g.getCurrentPrice());
}
} catch (Exception e) {
throw e;
}finally{
MyBatisUtils.closeSession(session);
}
}
3. Java 数据库开发与实战应用
- 参与学习 人
- 提交作业 357 份
- 解答问题 8016 个
本阶段将带你学习MySQL数据库,JDBC接口,MyBatis框架等,带你掌握的数据的存放和管理。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星