如何在 MySQL 数据库表中插入没有时间的日期?我尝试了这些代码,但出现以下异常:
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 'Mar 05 00:00:00 GMT-08:00 2014,1,1)' at line 1
注意:在 MySQL 表中,该列的数据类型我选择了日期数据类型
String Date = "\\d\\d\\d\\d\\D[0-1][0-9]\\D[0-3][0-9]";
while (DateMatcher.find()) {
String date = DateMatcher.group().trim();
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date myDate = formatter.parse(date);
db.insert_date(myDate,2,1);
}
我只对插入日期的日期部分查询有问题:
// insert DATE
public void insert_date(Date date_str, int sentence_id ,int document_id ){
// Statements allow to issue SQL queries to the database
try {
statement = connect.createStatement();
System.out.println( "insert into Date(date_Str,Sen_id,doc_id) " +
" values(" + date_str + "," + sentence_id + "," + document_id + ")"
);
statement.executeUpdate(
"insert into test.Date(date,Sen_id,doc_id)" +
" values(" + date_str + "," + sentence_id + "," + document_id + ")"
);
}
catch(Exception e ){System.out.println(e);};
// Result set get the result of the SQL query
}