Error generating .war file JHipster - java
I am trying to export the .war file but at the time of doing clean and build it throws me errors of liquibase. In the IDE run perfectly fine.
I stress that this happened after adding some roles as indicated in this question: Using ROLES in jhipster?
This is the error thrown by the console:
2018-02-27 11:20:40.764 WARN 8156 --- [as-4-Executor-1] i.g.j.c.liquibase.AsyncSpringLiquibase : Starting Liquibase asynchronously, your database might not be ready at startup!
2018-02-27 11:20:43.048 ERROR 8156 --- [as-4-Executor-1] liquibase : classpath:config/liquibase/master.xml: config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000001::jhipster: Change Set config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000001::jhipster failed. Error: Tabla "JHI_USER" ya existe
Table "JHI_USER" already exists; SQL statement:
CREATE TABLE PUBLIC.jhi_user (id BIGINT AUTO_INCREMENT NOT NULL, login VARCHAR(50) NOT NULL, password_hash VARCHAR(60), first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100), image_url VARCHAR(256), activated BOOLEAN NOT NULL, lang_key VARCHAR(6), activation_key VARCHAR(20), reset_key VARCHAR(20), created_by VARCHAR(50) NOT NULL, created_date TIMESTAMP DEFAULT NOW() NOT NULL, reset_date TIMESTAMP, last_modified_by VARCHAR(50), last_modified_date TIMESTAMP, CONSTRAINT PK_JHI_USER PRIMARY KEY (id), CONSTRAINT ux_user_login UNIQUE (login), CONSTRAINT ux_user_email UNIQUE (email)) [42101-196] [Failed SQL: CREATE TABLE PUBLIC.jhi_user (id BIGINT AUTO_INCREMENT NOT NULL, login VARCHAR(50) NOT NULL, password_hash VARCHAR(60), first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100), image_url VARCHAR(256), activated BOOLEAN NOT NULL, lang_key VARCHAR(6), activation_key VARCHAR(20), reset_key VARCHAR(20), created_by VARCHAR(50) NOT NULL, created_date TIMESTAMP DEFAULT NOW() NOT NULL, reset_date TIMESTAMP, last_modified_by VARCHAR(50), last_modified_date TIMESTAMP, CONSTRAINT PK_JHI_USER PRIMARY KEY (id), CONSTRAINT ux_user_login UNIQUE (login), CONSTRAINT ux_user_email UNIQUE (email))]
2018-02-27 11:20:43.110 ERROR 8156 --- [as-4-Executor-1] i.g.j.c.liquibase.AsyncSpringLiquibase : Liquibase could not start correctly, your database is NOT ready: Migration failed for change set config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000001::jhipster:
Reason: liquibase.exception.DatabaseException: Tabla "JHI_USER" ya existe
Table "JHI_USER" already exists; SQL statement:
CREATE TABLE PUBLIC.jhi_user (id BIGINT AUTO_INCREMENT NOT NULL, login VARCHAR(50) NOT NULL, password_hash VARCHAR(60), first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100), image_url VARCHAR(256), activated BOOLEAN NOT NULL, lang_key VARCHAR(6), activation_key VARCHAR(20), reset_key VARCHAR(20), created_by VARCHAR(50) NOT NULL, created_date TIMESTAMP DEFAULT NOW() NOT NULL, reset_date TIMESTAMP, last_modified_by VARCHAR(50), last_modified_date TIMESTAMP, CONSTRAINT PK_JHI_USER PRIMARY KEY (id), CONSTRAINT ux_user_login UNIQUE (login), CONSTRAINT ux_user_email UNIQUE (email)) [42101-196] [Failed SQL: CREATE TABLE PUBLIC.jhi_user (id BIGINT AUTO_INCREMENT NOT NULL, login VARCHAR(50) NOT NULL, password_hash VARCHAR(60), first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100), image_url VARCHAR(256), activated BOOLEAN NOT NULL, lang_key VARCHAR(6), activation_key VARCHAR(20), reset_key VARCHAR(20), created_by VARCHAR(50) NOT NULL, created_date TIMESTAMP DEFAULT NOW() NOT NULL, reset_date TIMESTAMP, last_modified_by VARCHAR(50), last_modified_date TIMESTAMP, CONSTRAINT PK_JHI_USER PRIMARY KEY (id), CONSTRAINT ux_user_login UNIQUE (login), CONSTRAINT ux_user_email UNIQUE (email))]
liquibase.exception.MigrationFailedException: Migration failed for change set config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000001::jhipster:
Reason: liquibase.exception.DatabaseException: Tabla "JHI_USER" ya existe
Table "JHI_USER" already exists; SQL statement:
CREATE TABLE PUBLIC.jhi_user (id BIGINT AUTO_INCREMENT NOT NULL, login VARCHAR(50) NOT NULL, password_hash VARCHAR(60), first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100), image_url VARCHAR(256), activated BOOLEAN NOT NULL, lang_key VARCHAR(6), activation_key VARCHAR(20), reset_key VARCHAR(20), created_by VARCHAR(50) NOT NULL, created_date TIMESTAMP DEFAULT NOW() NOT NULL, reset_date TIMESTAMP, last_modified_by VARCHAR(50), last_modified_date TIMESTAMP, CONSTRAINT PK_JHI_USER PRIMARY KEY (id), CONSTRAINT ux_user_login UNIQUE (login), CONSTRAINT ux_user_email UNIQUE (email)) [42101-196] [Failed SQL: CREATE TABLE PUBLIC.jhi_user (id BIGINT AUTO_INCREMENT NOT NULL, login VARCHAR(50) NOT NULL, password_hash VARCHAR(60), first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100), image_url VARCHAR(256), activated BOOLEAN NOT NULL, lang_key VARCHAR(6), activation_key VARCHAR(20), reset_key VARCHAR(20), created_by VARCHAR(50) NOT NULL, created_date TIMESTAMP DEFAULT NOW() NOT NULL, reset_date TIMESTAMP, last_modified_by VARCHAR(50), last_modified_date TIMESTAMP, CONSTRAINT PK_JHI_USER PRIMARY KEY (id), CONSTRAINT ux_user_login UNIQUE (login), CONSTRAINT ux_user_email UNIQUE (email))]
at liquibase.changelog.ChangeSet.execute(ChangeSet.java:619)
at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:51)
at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:79)
at liquibase.Liquibase.update(Liquibase.java:214)
at liquibase.Liquibase.update(Liquibase.java:192)
at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:431)
at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:388)
at io.github.jhipster.config.liquibase.AsyncSpringLiquibase.initDb(AsyncSpringLiquibase.java:82)
at io.github.jhipster.config.liquibase.AsyncSpringLiquibase.lambda$afterPropertiesSet$0(AsyncSpringLiquibase.java:64)
at io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor.lambda$createWrappedRunnable$1(ExceptionHandlingAsyncTaskExecutor.java:66)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: liquibase.exception.DatabaseException: Tabla "JHI_USER" ya existe
Table "JHI_USER" already exists; SQL statement:
CREATE TABLE PUBLIC.jhi_user (id BIGINT AUTO_INCREMENT NOT NULL, login VARCHAR(50) NOT NULL, password_hash VARCHAR(60), first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100), image_url VARCHAR(256), activated BOOLEAN NOT NULL, lang_key VARCHAR(6), activation_key VARCHAR(20), reset_key VARCHAR(20), created_by VARCHAR(50) NOT NULL, created_date TIMESTAMP DEFAULT NOW() NOT NULL, reset_date TIMESTAMP, last_modified_by VARCHAR(50), last_modified_date TIMESTAMP, CONSTRAINT PK_JHI_USER PRIMARY KEY (id), CONSTRAINT ux_user_login UNIQUE (login), CONSTRAINT ux_user_email UNIQUE (email)) [42101-196] [Failed SQL: CREATE TABLE PUBLIC.jhi_user (id BIGINT AUTO_INCREMENT NOT NULL, login VARCHAR(50) NOT NULL, password_hash VARCHAR(60), first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100), image_url VARCHAR(256), activated BOOLEAN NOT NULL, lang_key VARCHAR(6), activation_key VARCHAR(20), reset_key VARCHAR(20), created_by VARCHAR(50) NOT NULL, created_date TIMESTAMP DEFAULT NOW() NOT NULL, reset_date TIMESTAMP, last_modified_by VARCHAR(50), last_modified_date TIMESTAMP, CONSTRAINT PK_JHI_USER PRIMARY KEY (id), CONSTRAINT ux_user_login UNIQUE (login), CONSTRAINT ux_user_email UNIQUE (email))]
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:309)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:55)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:113)
at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1277)
at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1259)
at liquibase.changelog.ChangeSet.execute(ChangeSet.java:582)
... 12 common frames omitted
Caused by: org.h2.jdbc.JdbcSQLException: Tabla "JHI_USER" ya existe
Table "JHI_USER" already exists; SQL statement:
CREATE TABLE PUBLIC.jhi_user (id BIGINT AUTO_INCREMENT NOT NULL, login VARCHAR(50) NOT NULL, password_hash VARCHAR(60), first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100), image_url VARCHAR(256), activated BOOLEAN NOT NULL, lang_key VARCHAR(6), activation_key VARCHAR(20), reset_key VARCHAR(20), created_by VARCHAR(50) NOT NULL, created_date TIMESTAMP DEFAULT NOW() NOT NULL, reset_date TIMESTAMP, last_modified_by VARCHAR(50), last_modified_date TIMESTAMP, CONSTRAINT PK_JHI_USER PRIMARY KEY (id), CONSTRAINT ux_user_login UNIQUE (login), CONSTRAINT ux_user_email UNIQUE (email)) [42101-196]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.get(DbException.java:155)
at org.h2.command.ddl.CreateTable.update(CreateTable.java:117)
at org.h2.command.CommandContainer.update(CommandContainer.java:101)
at org.h2.command.Command.executeUpdate(Command.java:260)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:192)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:164)
at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:92)
at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java)
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:307)
... 17 common frames omitted
´
2018-02-27 11:20:49.728 DEBUG 8156 --- [ restartedMain] i.g.j.c.apidoc.SwaggerConfiguration : Starting Swagger
2018-02-27 11:20:49.729 DEBUG 8156 --- [ restartedMain] i.g.j.c.apidoc.SwaggerConfiguration : Started Swagger in 0 ms
2018-02-27 11:20:51.944 INFO 8156 --- [ restartedMain] municipalidad.obras.ObrasPrivadas4App : Started ObrasPrivadas4App in 17.765 seconds (JVM running for 18.308)
2018-02-27 11:20:51.945 INFO 8156 --- [ restartedMain] municipalidad.obras.ObrasPrivadas4App :
----------------------------------------------------------
Application 'obrasPrivadas4' is running! Access URLs:
Local: http://localhost:8080
External: http://192.168.48.28:8080
Profile(s): [swagger, dev]
----------------------------------------------------------
´
I would greatly appreciate your help. Sorry for the bad English.
Related
Can't create table "system_user" in h2
i am having a problem creating a simple table in h2. create table system_user (id bigint not null, username varchar(255), primary key (id)); When executing i am getting the error: Syntax Fehler in SQL Befehl "create table [*]system_user (id bigint not null, username varchar(255), primary key (id))"; erwartet "identifier" Syntax error in SQL statement "create table [*]system_user (id bigint not null, username varchar(255), primary key (id))"; expected "identifier"; SQL statement: create table system_user (id bigint not null, username varchar(255), primary key (id)) [42001-210] 42001/42001 (Hilfe) org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax Fehler in SQL Befehl "create table [*]system_user (id bigint not null, username varchar(255), primary key (id))"; erwartet "identifier" Syntax error in SQL statement "create table [*]system_user (id bigint not null, username varchar(255), primary key (id))"; expected "identifier"; SQL statement: create table system_user (id bigint not null, username varchar(255), primary key (id)) [42001-210] at org.h2.message.DbException.getJdbcSQLException(DbException.java:521) at org.h2.message.DbException.getJdbcSQLException(DbException.java:496) at org.h2.message.DbException.getSyntaxError(DbException.java:265) at org.h2.command.Parser.readIdentifier(Parser.java:5759) at org.h2.command.Parser.readIdentifierWithSchema(Parser.java:5719) at org.h2.command.Parser.readIdentifierWithSchema(Parser.java:5748) at org.h2.command.Parser.parseCreateTable(Parser.java:9280) at org.h2.command.Parser.parseCreate(Parser.java:6779) at org.h2.command.Parser.parsePrepared(Parser.java:746) at org.h2.command.Parser.parse(Parser.java:674) at org.h2.command.Parser.parse(Parser.java:644) at org.h2.command.Parser.prepareCommand(Parser.java:551) at org.h2.engine.SessionLocal.prepareLocal(SessionLocal.java:615) at org.h2.engine.SessionLocal.prepareCommand(SessionLocal.java:553) at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1116) at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:237) at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:223) at org.h2.server.web.WebApp.getResult(WebApp.java:1339) at org.h2.server.web.WebApp.query(WebApp.java:1137) at org.h2.server.web.WebApp$1.next(WebApp.java:1103) at org.h2.server.web.WebApp$1.next(WebApp.java:1090) at org.h2.server.web.WebThread.process(WebThread.java:189) at org.h2.server.web.WebThread.run(WebThread.java:102) at java.base/java.lang.Thread.run(Thread.java:833) Does anyone have the same problem?
How can I set up JdbcUserDetailsManager to use my table?
I'm learning about Spring Security with JdbcUserDetailsManager and I know that the default name for the MySQL table is users. The problem is that my MySQL table name is user, not users and I don't know how can I set up JdbcUserDetailsManager to work with this table. So how can I set up this bean? #Bean public UserDetailsService userDetailsService() { JdbcUserDetailsManager service = new JdbcUserDetailsManager(primaryDataSource()); return service; } And here is my MySQL schema: CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(50) NOT NULL, `password` char(80) NOT NULL, `first_name` varchar(50) NOT NULL, `last_name` varchar(50) NOT NULL, `email` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1; CREATE TABLE `role` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; CREATE TABLE `users_roles` ( `user_id` int(11) NOT NULL, `role_id` int(11) NOT NULL, PRIMARY KEY (`user_id`,`role_id`), KEY `FK_ROLE_idx` (`role_id`), CONSTRAINT `FK_ROLE` FOREIGN KEY (`role_id`) REFERENCES `role` (`id`), CONSTRAINT `FK_USER_05` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; Any feedback will be apreciated. Thank you very much!
JdbcUserDetailsManager is only useful when the role has grouping concept (Think that a role can have many permissions and an user can have many roles. We check if an user is allowed to do something by checking if he has certain permissions). But based on your DB schema , the role does not such grouping concept. Instead , you should use much simpler JdbcDaoImpl. You have to override the following SQL according to your DB schema : #Bean public UserDetailsService userDetailsService() { UserDetailsService service = new JdbcDaoImpl(primaryDataSource()); service.setUsersByUsernameQuery("select username, password , true from user where username = ? "); service.setAuthoritiesByUsernameQuery("select user.username , role.name " + " from users_role " + " inner join role on role.id = users_role.role_id " + " inner join user on user.id = users_role.user_id " + " where user.username = ?"); return service; } For details about how to override these SQL , refer to the javadocs.
Java + MySQL - Overwriting rows when updating
I'm starting to create a database program for managing engineers, assigning calls to them and such and having this all linked together. However, I have ran into a problem where when I try to update/change a bit of information in the database through the use of my program it instead changed all the other items in the table to what it has just been changed to. For example, if I changed engineer 1's name to 'a', it would overwrite the other entities in the table so engineer 2 would have its name as 'a' now along with the properties of engineer 1. I have attached the code I have written to update the table along with the SQL code for my database. I'd appreaciate if someone could help me understand what is wrong here and I can provide other information when requested. Thanks private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) { try{ con = Connect.ConnectDB(); String sql = "update engineers set first_name ='" + textFirstName.getText()+ "',last_name='"+ textLastName.getText()+ "',middle_name='" + textMiddleName.getText()+ "',postcode='" + textPostcode.getText() + "',engineer_address='" + textAddress.getText() + "',engineer_dob='" + textDOB.getText() + "',comments='" + textComments.getText()+ "'"; pst = con.prepareStatement(sql); pst.execute(); JOptionPane.showMessageDialog(this, "Updated","Engineer",JOptionPane.INFORMATION_MESSAGE); btnUpdate.setEnabled(false); }catch(HeadlessException | SQLException ex){ JOptionPane.showMessageDialog(this,ex); } -- MySQL Script generated by MySQL Workbench -- Fri Sep 22 12:56:05 2017 -- Model: New Model Version: 1.0 -- MySQL Workbench Forward Engineering SET #OLD_UNIQUE_CHECKS=##UNIQUE_CHECKS, UNIQUE_CHECKS=0; SET #OLD_FOREIGN_KEY_CHECKS=##FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; SET #OLD_SQL_MODE=##SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES'; -- ----------------------------------------------------- -- Schema mydb -- ----------------------------------------------------- -- ----------------------------------------------------- -- Schema mydb -- ----------------------------------------------------- CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 ; USE `mydb` ; -- ----------------------------------------------------- -- Table `mydb`.`customers` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mydb`.`customers` ( `customer_id` INT NOT NULL AUTO_INCREMENT, `customer_name` VARCHAR(45) NOT NULL, `telephone` VARCHAR(45) NOT NULL, `postcode` VARCHAR(45) NOT NULL, `address` VARCHAR(45) NOT NULL, `city` VARCHAR(45) NOT NULL, PRIMARY KEY (`customer_id`)) ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `mydb`.`engineers` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mydb`.`engineers` ( `engineer_id` INT NOT NULL AUTO_INCREMENT, `first_name` VARCHAR(45) NOT NULL, `last_name` VARCHAR(45) NOT NULL, `postcode` VARCHAR(45) NOT NULL, `active_job` VARCHAR(45) NOT NULL, `on_holiday` VARCHAR(45) NOT NULL, `engineer_address` VARCHAR(45) NOT NULL, `engineer_postcode` VARCHAR(45) NOT NULL, `comments` VARCHAR(45) NOT NULL, `middle_name` VARCHAR(45) NOT NULL, PRIMARY KEY (`engineer_id`)) ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `mydb`.`machines` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mydb`.`machines` ( `serial_number` VARCHAR(45) NOT NULL, `customer_id` INT NOT NULL, `meter_reading` VARCHAR(45) NOT NULL, `install_date` VARCHAR(45) NOT NULL, PRIMARY KEY (`serial_number`), INDEX `fk_customer_id_idx` (`customer_id` ASC), CONSTRAINT `fk_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `mydb`.`customers` (`customer_id`) ON DELETE RESTRICT ON UPDATE CASCADE) ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `mydb`.`new_call` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mydb`.`new_call` ( `call_id` INT NOT NULL AUTO_INCREMENT, `serial_number` VARCHAR(45) NOT NULL, `customer_id` INT NOT NULL, `engineer_id` INT NOT NULL, `call_fault` VARCHAR(45) NOT NULL, `call_type` VARCHAR(45) NOT NULL, `date_recieved` VARCHAR(45) NOT NULL, `start_date` VARCHAR(45) NOT NULL, `engineer_dob` VARCHAR(45) NOT NULL, PRIMARY KEY (`call_id`), INDEX `fk_serial_number_idx` (`serial_number` ASC), INDEX `fk_engineer_id_idx` (`engineer_id` ASC), INDEX `fk1_customer_id_idx` (`customer_id` ASC), CONSTRAINT `fk_serial_number` FOREIGN KEY (`serial_number`) REFERENCES `mydb`.`machines` (`serial_number`) ON DELETE RESTRICT ON UPDATE CASCADE, CONSTRAINT `fk_engineer_id` FOREIGN KEY (`engineer_id`) REFERENCES `mydb`.`engineers` (`engineer_id`) ON DELETE RESTRICT ON UPDATE CASCADE, CONSTRAINT `fk1_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `mydb`.`customers` (`customer_id`) ON DELETE RESTRICT ON UPDATE CASCADE) ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `mydb`.`users` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mydb`.`users` ( `username` VARCHAR(45) NOT NULL, `password` VARCHAR(45) NOT NULL) ENGINE = InnoDB; SET SQL_MODE=#OLD_SQL_MODE; SET FOREIGN_KEY_CHECKS=#OLD_FOREIGN_KEY_CHECKS; SET UNIQUE_CHECKS=#OLD_UNIQUE_CHECKS;
first of all use PreparedStatement. if you want to update a specific engineer you should identify the data with the sql where section. in your case that could be: PreparedStatement statement = con.prepareStatement("update engineers set first_name =? " + ",last_name=?, middle_name=?" + ",postcode=?,engineer_address=?" + ",engineer_dob=?" + ",comments=? " + "where engineer_id=?"); // <--- WHERE SECTION statement.setString(1, "Chuck"); statement.setString(2, "Norris"); // and so on and so on... statement.setInteger(8, idOfEngineer); statement.executeUpdate();
How to insert data in Apache calcite
I'm inserting data form SQL to File through Apache calcite Class.forName("org.apache.calcite.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:calcite:"); CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class); SchemaPlus rootSchema = calciteConnection.getRootSchema(); JdbcSchema jdbcSchema = JdbcSchema.create(rootSchema, "TRUNKDB", dataSource, null, "dbo"); rootSchema.add("XXXX", jdbcSchema); /*CSV Schema*/ File csvDir = new File("/home/nanobi/Drill/CSV/"); // SchemaPlus schema = rootSchema.add("s", new CsvSchema(csvDir,null)); rootSchema.add("CSV", new CsvSchema(csvDir, Flavor.SCANNABLE)); Statement statement = connection.createStatement(); int resultSet = statement.executeUpdate("INSERT into \"CSV\".\"p\"(\"Name\") select \"name\" from \"TRUNKDB\".\"nbmdc_nanomarts\""); i'm getting bellow error Exception in thread "main" java.sql.SQLException: Error while executing SQL "INSERT into "CSV"."p"("Name") select 'p' from "TRUNKDB"."nbmdc_nanomarts"": Node [rel#29:Subset#3.ENUMERABLE.[]] could not be implemented; planner state: Root: rel#29:Subset#3.ENUMERABLE.[] Original rel: Sets: Set#0, type: RecordType(VARCHAR(45) row_id, VARCHAR(45) si_id, VARCHAR(500) name, VARCHAR(500) description, VARCHAR(255) icon_path, VARCHAR(255) icon_content, VARCHAR(255) active_flag, TIMESTAMP(3) created_datetime, VARCHAR(45) created_by_user_id, TIMESTAMP(3) updated_datetime, VARCHAR(45) updated_by_user_id, VARCHAR(500) nanomart_xml_filepath, VARCHAR(255) db_username, VARCHAR(255) db_user_password, VARCHAR(255) dbase_name, VARCHAR(255) db_url, VARCHAR(255) db_schema_name, CHAR(1) is_mandatory, CHAR(1) is_load_lock, VARCHAR(45) mart_type, VARCHAR(255) db_driver, VARCHAR(255) load_frequency, CHAR(1) is_date_table, CHAR(1) is_alias, VARCHAR(500) nbmdc_n, VARCHAR(45) master_flag, VARCHAR(50) nbmdm_repository_row_id, CHAR(1) is_hierarchical, VARCHAR(4000) inplacedetail) rel#8:Subset#0.JDBC.TRUNKDB.[], best=rel#0, importance=0.6561 rel#0:JdbcTableScan.JDBC.TRUNKDB.[](table=[TRUNKDB, nbmdc_nanomarts]), rowcount=100.0, cumulative cost={100.0 rows, 101.0 cpu, 0.0 io}
Unfortunately Calcite doesn't currently support modification of CSV files. Modification has only been worked on for JDBC tables.
Hibernate Mapping Map<String,String>
I use Hibernate 4.3.11 with H2 Database. I have a class in Java with several maps with annotations. Persisting works fine but my map in my H2 Database has no entries. #ElementCollection #MapKeyColumn(name = "key") #CollectionTable(name = "value", joinColumns = #JoinColumn(name = "sabilanz_id")) #Column(name = "value") private Map<String, String> sonstAnlagen; My H2 output: select * from saBilanz_sonstanlagen; SABILANZ_ID VALUE KEY (keine Datensätze, 8 ms)
MYSQL Dump CREATE USER IF NOT EXISTS SA SALT '7f72b2df54de3e6a' HASH '11116078543527d2f2c87f3df156e18f71f7d1bc0e5a7a7653d22512c9de2994' ADMIN; CREATE SEQUENCE PUBLIC.SYSTEM_SEQUENCE_8A6BCC6F_6599_4635_8D43_45F8DC56F9AD START WITH 65 BELONGS_TO_TABLE; CREATE SEQUENCE PUBLIC.SYSTEM_SEQUENCE_644997FC_AAC3_4D75_B453_FD4E56B7D326 START WITH 65 BELONGS_TO_TABLE; CREATE SEQUENCE PUBLIC.SYSTEM_SEQUENCE_61E73E74_EF49_4B3E_AA95_432C69B31DDB START WITH 65 BELONGS_TO_TABLE; CREATE SEQUENCE PUBLIC.SYSTEM_SEQUENCE_3CF73C6A_6FE2_4978_BD20_EAC744ED7F25 START WITH 65 BELONGS_TO_TABLE; CREATE SEQUENCE PUBLIC.SYSTEM_SEQUENCE_676C7731_65A8_41CA_9097_14C131188E32 START WITH 65 BELONGS_TO_TABLE; CREATE CACHED TABLE PUBLIC.BILANZ( ID BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_676C7731_65A8_41CA_9097_14C131188E32) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_676C7731_65A8_41CA_9097_14C131188E32, AKTIVA VARCHAR(255), ANLAGEVERMOEGEN VARCHAR(255), BUCHUNGSKREIS VARCHAR(255), EIGENKAPITAL VARCHAR(255), FINANZANLAGEN VARCHAR(255), FORDERUNGEN VARCHAR(255), GEWINNRUECKLAGEN VARCHAR(255), GEZEICHNETESKAPITAL VARCHAR(255), IMMATERIELLEVERMOEGENSGEGENSTAENDE VARCHAR(255), JAHRESUEBERSCHUSS VARCHAR(255), KAPITALRUECKLAGE VARCHAR(255), LIQUIDEMITTEL VARCHAR(255), PASSIVA VARCHAR(255), PERIODE VARCHAR(255), RUECKSTELLUNGEN VARCHAR(255), SACHANLAGEN VARCHAR(255), UMLAUFVERMOEGEN VARCHAR(255), VERBINDLICHKEITEN VARCHAR(255), VORRAETE VARCHAR(255), WAEHRUNG VARCHAR(255), WERTPAPIERE VARCHAR(255) ); ALTER TABLE PUBLIC.BILANZ ADD CONSTRAINT PUBLIC.CONSTRAINT_7 PRIMARY KEY(ID); -- 2 +/- SELECT COUNT(*) FROM PUBLIC.BILANZ; INSERT INTO PUBLIC.BILANZ(ID, AKTIVA, ANLAGEVERMOEGEN, BUCHUNGSKREIS, EIGENKAPITAL, FINANZANLAGEN, FORDERUNGEN, GEWINNRUECKLAGEN, GEZEICHNETESKAPITAL, IMMATERIELLEVERMOEGENSGEGENSTAENDE, JAHRESUEBERSCHUSS, KAPITALRUECKLAGE, LIQUIDEMITTEL, PASSIVA, PERIODE, RUECKSTELLUNGEN, SACHANLAGEN, UMLAUFVERMOEGEN, VERBINDLICHKEITEN, VORRAETE, WAEHRUNG, WERTPAPIERE) VALUES (1, '981561.00', '738090.00', '1000', '694549.00', '645086.00', '82568.00', '539628.00', '75054.00', '33256.00', '79468.00', '399.00', '5396.00', '981561.00', '2015.01', '97138.00', '59748.00', '243471.00', '189874.00', '124393.00', 'EUR', '31114.00'), (33, '981561.00', '738090.00', '1000', '694549.00', '645086.00', '82568.00', '539628.00', '75054.00', '33256.00', '79468.00', '399.00', '5396.00', '981561.00', '2015.01', '97138.00', '59748.00', '243471.00', '189874.00', '124393.00', 'EUR', '31114.00'); CREATE CACHED TABLE PUBLIC.GUV( ID BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_61E73E74_EF49_4B3E_AA95_432C69B31DDB) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_61E73E74_EF49_4B3E_AA95_432C69B31DDB, ABSCHREIBUNGEN VARCHAR(255), BESTANDSVERAENDERUNGEN VARCHAR(255), BETRIEBSERGEBNIS VARCHAR(255), BILANZGEWINNBILANZVERLUST VARCHAR(255), ERGEBNISDERGEWOEHNLICHENGESCHAEFTSTAETIGKEIT VARCHAR(255), ERTRAEGEAUSBETEILIGUNGEN VARCHAR(255), FINANZERGEBNIS VARCHAR(255), MATERIALAUFWAND VARCHAR(255), PERSONALAUFWAND VARCHAR(255), SONSTIGEBETRIEBLICHEAUFWENDUNGEN VARCHAR(255), SONSTIGEBETRIEBLICHEERTRAEGE VARCHAR(255), STEUERN VARCHAR(255), UMSATZERLOESE VARCHAR(255), ZINSAUFWENDUNGEN VARCHAR(255), ZINSERTRAEGE VARCHAR(255) ); ALTER TABLE PUBLIC.GUV ADD CONSTRAINT PUBLIC.CONSTRAINT_1 PRIMARY KEY(ID); -- 2 +/- SELECT COUNT(*) FROM PUBLIC.GUV; INSERT INTO PUBLIC.GUV(ID, ABSCHREIBUNGEN, BESTANDSVERAENDERUNGEN, BETRIEBSERGEBNIS, BILANZGEWINNBILANZVERLUST, ERGEBNISDERGEWOEHNLICHENGESCHAEFTSTAETIGKEIT, ERTRAEGEAUSBETEILIGUNGEN, FINANZERGEBNIS, MATERIALAUFWAND, PERSONALAUFWAND, SONSTIGEBETRIEBLICHEAUFWENDUNGEN, SONSTIGEBETRIEBLICHEERTRAEGE, STEUERN, UMSATZERLOESE, ZINSAUFWENDUNGEN, ZINSERTRAEGE) VALUES (1, '13461.00', '15717.00', '45276.00', '79468.00', '104102.00', '65202.00', '58826.00', '476269.00', '121990.00', '229256.00', '112319.00', '24634.00', '758216.00', '9583.00', '3207.00'), (33, '13461.00', '15717.00', '45276.00', '79468.00', '104102.00', '65202.00', '58826.00', '476269.00', '121990.00', '229256.00', '112319.00', '24634.00', '758216.00', '9583.00', '3207.00'); CREATE CACHED TABLE PUBLIC.ROI( ID BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_8A6BCC6F_6599_4635_8D43_45F8DC56F9AD) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_8A6BCC6F_6599_4635_8D43_45F8DC56F9AD, ROI VARCHAR(255) ); ALTER TABLE PUBLIC.ROI ADD CONSTRAINT PUBLIC.CONSTRAINT_13 PRIMARY KEY(ID); -- 2 +/- SELECT COUNT(*) FROM PUBLIC.ROI; INSERT INTO PUBLIC.ROI(ID, ROI) VALUES (1, '0.15'), (33, '0.15'); CREATE CACHED TABLE PUBLIC.SABILANZ_SONSTANLAGEN( SABILANZ_ID BIGINT NOT NULL, VALUE VARCHAR(255), KEY VARCHAR(255) NOT NULL ); ALTER TABLE PUBLIC.SABILANZ_SONSTANLAGEN ADD CONSTRAINT PUBLIC.CONSTRAINT_7C PRIMARY KEY(SABILANZ_ID, KEY); -- 0 +/- SELECT COUNT(*) FROM PUBLIC.SABILANZ_SONSTANLAGEN; CREATE CACHED TABLE PUBLIC.UHV( ID BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_3CF73C6A_6FE2_4978_BD20_EAC744ED7F25) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_3CF73C6A_6FE2_4978_BD20_EAC744ED7F25, UMSCHLAGSHAEUFIGKEITSVERMOEGEN VARCHAR(255) ); ALTER TABLE PUBLIC.UHV ADD CONSTRAINT PUBLIC.CONSTRAINT_14 PRIMARY KEY(ID); -- 2 +/- SELECT COUNT(*) FROM PUBLIC.UHV; INSERT INTO PUBLIC.UHV(ID, UMSCHLAGSHAEUFIGKEITSVERMOEGEN) VALUES (1, '2.5'), (33, '2.5'); CREATE CACHED TABLE PUBLIC.UMSATZRENDITE( ID BIGINT DEFAULT (NEXT VALUE FOR PUBLIC.SYSTEM_SEQUENCE_644997FC_AAC3_4D75_B453_FD4E56B7D326) NOT NULL NULL_TO_DEFAULT SEQUENCE PUBLIC.SYSTEM_SEQUENCE_644997FC_AAC3_4D75_B453_FD4E56B7D326, UMSATZRENDITE VARCHAR(255) ); ALTER TABLE PUBLIC.UMSATZRENDITE ADD CONSTRAINT PUBLIC.CONSTRAINT_6 PRIMARY KEY(ID); -- 2 +/- SELECT COUNT(*) FROM PUBLIC.UMSATZRENDITE; INSERT INTO PUBLIC.UMSATZRENDITE(ID, UMSATZRENDITE) VALUES (1, '6'), (33, '6'); ALTER TABLE PUBLIC.SABILANZ_SONSTANLAGEN ADD CONSTRAINT PUBLIC.FK_698G1BM2MSCHIYFFSB12ONGIR FOREIGN KEY(SABILANZ_ID) REFERENCES PUBLIC.BILANZ(ID) NOCHECK;
You didn't insert any value into saBilanz_sonstanlagen table. It's normal that it doesn't have any record.