如何在没有时间的情况下将日期插入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表中,此列的数据类型我选择了date数据类型
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
}