碰到的sql错误,记录一下
1.
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
导入的mysql的jar包8.0版本的话,jdbc.properties中
不用com.mysql.jdbc.Driver
,
得用driverClassName=com.mysql.cj.jdbc.Driver
2.Cannot determine value type from string 'id' Query
java.sql.SQLException: Cannot determine value type from string 'id' Query: SELECT 'id','username','password','email' from t_user where username=? Parameters: [admin]
at org.apache.commons.dbutils.QueryRunner.rethrow(QueryRunner.java:542)
at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:399)
at com.study.dao.Impl.BaseDao.queryForOne(BaseDao.java:50)
at com.study.dao.Impl.UserDaoImpl.queryUserByUsername(UserDaoImpl.java:14)
at com.study.test.UserDaoTest.queryUserByUsername(UserDaoTest.java:17)
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:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
null
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Process finished with exit code 0
sql语句:
String sql = "SELECT 'id','username','password','email' from t_user where username=?";
将'
单引号改为键盘左上角的 `
String sql = "SELECT `id`,`username`,`password`,`email` from t_user where username=?";
java.sql.SQLException: Column 'name' cannot be null Query: insert into t_book(
name,
author,
price,
sales,
stock,
img_path) values(?,?,?,?,?,?) Parameters: [null, null, null, null, null, static/img/logo.gif]
<tr>
<td><input name="name" type="text" value="时间简史"/></td>
<td><input name="price" type="text" value="30.00"/></td>
<td><input name="author" type="text" value="霍金"/></td>
<td><input name="sales" type="text" value="200"/></td>
<td><input name="stock" type="text" value="300"/></td>
<td><input type="submit" value="提交"/></td>
</tr>
表单中name属性要与sql语句或者说数据库里字段一致
当用户提交完请求,浏览器会记录下最后一次请求的全部信息。当用户按下功能键 F5,就会发起浏览器记录的最后一次请求。使用内部转发会出现重复发送表单问题,可以使用请求重定向解决。这时最后一次请求是请求第二个页面,而不是提交表单
5.java.lang.NumberFormatException: null
工具类字符串转整型可能存在转型失败或空值问题
public static int parseInt(String strInt){
int result = 0;
try {
result = Integer.parseInt(strInt);
} catch (Exception e) {
e.printStackTrack();
}
return result;
}
添加默认值参数,若转型失败,返回默认值
public static int parseInt(String strInt,int defaultValue){
int result = 0;
try {
result = Integer.parseInt(strInt);
} catch (Exception e) {
return defaultValue;
}
return result;
}
- 使用
TimeStamp()
类获得的时间显示为1970,原因:获取的时间戳为单位为秒,转换时使用毫秒,导致时间缩小1000倍