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"

Public static zero breaks (string connection string, string dbuser, string dbps, string squashespath) throws an exception {/ search and SQL script file file = new file (escript scriptpath); File [] script = file.listFiles (new FileFilter () {@Override accept public boolean (file file) {return file.getName (). EndsWith (".sql");}}); & Lt; File & gt; Script list = erases List (script); Collections.sort (scriptsList); Class.forName ("com.mysql.jdbc.Driver") newInstance () .; Connection conn = DriverManager.getConnection (connectionString, dbUser, dbPass); // Load each script and apply it to {file: script list} {System.out.println ("import script:" + f); & Lt; String & gt; Line = files.RedAlline (path. (F.A.A.A.A.O.O.O.O.O..T.) ()., Charset. Name ("UTF-8"); Stringbilder sb = new stringbiller (); For (string line: line) sb.append (line) .append ("\ n"); String sqlStatement = sb.toString (); System.out.print (sqlStatement); Description st = conn.createStatement (); St.execute (sqlStatement); St.close (); }}

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

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -