How to create table with DATETIME DEFAULT using Java (JDBC, MySQL) -
I have some MySQL lipets that are necessary to recreate the database. When I call them mysql
Execute the command line using the command, they work fine.
I now wrote a Java class, which has executed these scripts using the JDBC connection for the MySQL database.
The script has a line in the "Create a table" --Statument:
registration_data DATETIME DEFAULT CURRENT_TIMESTAMP
This line though JDBC -MySQL will not be executed using a connection I get an error: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: invalid default value for 'registration_date'
related The method shown below is called a sqlScriptpath
number of folders containing SQL scripts. The connection string has this content: "jdbc: mysql: // localhost: 3306 / testDb? UseUnicode = yes & characterEncoding = UTF-8 & allowMultiQueries = true"
and the relevant portion of the script:
create the table user (ID INT primary key faucet AUTO_INCREMENT, username VARCHAR (255), password VARCHAR ( 255), age group INT, registration_data DATETIME DEFAULT CURRENT_TIMESTAMP) engine = InnoDB DEFAULT CHARSET = utf8;
What's the problem here?
I used to test a MySQL database that was inherited in Java, with no default definition, The data defined in the form was failing this error on the time column, I now added the default () and after that it worked fine.
Comments
Post a Comment