"AFTER" not suport using ucannacess ALTER TABLE? - java

Why "AFTER" not support in ucannacess ALTER TABLE?
I want to add column in position to exist column table; using database .accdb
sql = "ALTER TABLE tableName ADD COLUMN newColumnName VARCHAR(50) AFTER columnNameExist";
Example
sql = "ALTER TABLE car ADD COLUMN information VARCHAR(50) AFTER name ";
Exception
net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::4.0.4
java.sql.SQLSyntaxErrorException: unexpected token : AFTER

Do not use ADD COLUMN instead of this use only "ADD" in place of "ADD COLUMN"
Example : ALTER TABLE members ADD date_of_registration date NULL AFTER date_of_birth;
Hope this works.

Related

Column not found after update db

I'm new to java . i've two questions . i'm using flyway and h2 db i added two file sql one of them to create table with two columns like that
CREATE TABLE contacts (
id bigint auto_increment NOT NULL,
name varchar(128) NOT NULL,
PRIMARY KEY(id)
);
and the other is to alter new column like that
ALTER TABLE contacts
ADD COLUMN contacts Varchar(255);
1- i used flyway.migrate worked fine but i faced mismatch so i used flyway.repair() is that normal to use it every time ?
2- when i wrote statment sql for executing insert sql command like that
stmt.execute("INSERT INTO contacts(name,contacts) VALUES('ABC','ABC#yahoo.com')");
i got
Exception in thread "main" org.h2.jdbc.JdbcSQLException: Column "CONTACTS" not found; SQL statement:
INSERT INTO contacts(name,contacts) VALUES('ABC ','ABC#yahoo.com') [42122-173]
You need to add AFTER in your second sql file.
ALTER TABLE contacts
ADD COLUMN contacts Varchar(255) AFTER name;

MySQL inserting data while only knowing 1 column name

I am wanting to insert some data into a MySQL table, these are the columns:
uuid | id_1 | id_41
the "id_1" and "id_41" could be anything, all I know is the primary key (uuid) and I am wanting to be able to insert into the table while only knowing the uuid column value as I am doing this so far:
PreparedStatement newPlayer = "INSERT INTO `test` values(?);";
newPlayer.setString(1, event.getPlayer().getUniqueId().toString());
But when I test it, it doesn't add to the table and does not produce any errors. I also know that all of the other values have a default value of 0
If you want to add a row without all columns included, you need to specify the column's name
INSERT INTO `test` (`uuid`) values(?);
Simple tell to insert the column you want insert eg for uuid
INSERT INTO `test` ( `uuid`) values(?);

Is there a Spring Batch 3 Upgrade Script for MySQL?

I haven't seen a script to do the DDL modification necessary to go from Spring Batch 2 -> 3 in MySQL. Curious if one exists?
After running a quick comparison of the schemas, these appear to be the changes for upgrading from Spring Batch 2.2.7.RELEASE -> 3.0.1.RELEASE on MySQL.
ALTER TABLE `BATCH_JOB_EXECUTION` MODIFY COLUMN `EXIT_CODE` varchar(2500) DEFAULT NULL;
ALTER TABLE `BATCH_JOB_EXECUTION` ADD COLUMN `JOB_CONFIGURATION_LOCATION` varchar(2500) DEFAULT NULL;
ALTER TABLE `BATCH_JOB_EXECUTION_SEQ` ADD COLUMN `UNIQUE_KEY` char(1) NOT NULL;
ALTER TABLE `BATCH_JOB_EXECUTION_SEQ` ADD UNIQUE KEY `UNIQUE_KEY_UN` (`UNIQUE_KEY`);
ALTER TABLE `BATCH_JOB_SEQ` ADD COLUMN `UNIQUE_KEY` char(1) NOT NULL;
ALTER TABLE `BATCH_JOB_SEQ` ADD UNIQUE KEY `UNIQUE_KEY_UN` (`UNIQUE_KEY`);
ALTER TABLE `BATCH_STEP_EXECUTION` MODIFY COLUMN `EXIT_CODE` varchar(2500) DEFAULT NULL;
ALTER TABLE `BATCH_STEP_EXECUTION_SEQ` ADD COLUMN `UNIQUE_KEY` char(1) NOT NULL;
ALTER TABLE `BATCH_STEP_EXECUTION_SEQ` ADD UNIQUE KEY `UNIQUE_KEY_UN` (`UNIQUE_KEY`);
For anyone who wants to know the DDL changes for postgresql:
ALTER TABLE BATCH_JOB_EXECUTION ALTER COLUMN EXIT_CODE TYPE varchar(2500);
ALTER TABLE BATCH_JOB_EXECUTION ADD COLUMN JOB_CONFIGURATION_LOCATION varchar(2500) DEFAULT NULL;
ALTER TABLE BATCH_STEP_EXECUTION ALTER COLUMN EXIT_CODE TYPE varchar(2500);
This worked for me when I upgraded from 2.2.7.RELEASE -> 3.0.7.RELEASE.
Really surprised there's no migration guide/or scripts, at least that I could find.

INSERT INTO SELECT STATEMENT with multiple FK

This is my code with 1 FK.
here's the columns
([PK]charityRoomID, charityRoomStatus, [FK]charityWardID)
INSERT INTO tbl_addcharityroom1 (charityRoomStatus, charityWardID)
VALUES ('"+jTextField10aw.getText() +"', (
select charityWardID
from tbl_addcharityward
where diseaseCategory='"+ jComboBox1.getSelectedItem().toString() +"'))";
Now, I added a new column(RateID) which is another FK, but i don't know the correct statement for multiple FK. here's the columns
([PK]charityWardID, charityRoomStatus, [FK]charityWardID, [FK]rateID)
I am using netbeans & mySQL
A FK is just a constraint on a database column. It basically means that your column content must map to a specified column when you insert data.
So, if your insert statement specifies a value that exist in the ID column of your Rate table, everything will be allright. Otherwise, an exception will occur.
Basically you just need to do this, replacing "yourRateIdValue" by an Id that actually exist in your Rate table:
"INSERT INTO tbl_addcharityroom1 (charityRoomStatus, charityWardID, rateID)
VALUES ('" + jTextField10aw.getText() + "', (
select charityWardID
from tbl_addcharityward
where diseaseCategory='"+ jComboBox1.getSelectedItem().toString() +"'), yourRateIdValue)";
You can also replace the "yourRateIdValue" by a select statement, as you did for the "charityWardID" column

Java SQL simple update syntax issue

I have a table named books with bookID, bookName, count , orderCount
i'd like to write an sql query that will update all books.orderCount to books.orderCount+1.
How shall i do that using executeQuery("UPDATE books...."); ?
I'm having troubles with the syntax.
I've tried to search info on the net however most articles are about INSERT or DELETE commands and the only article that was related suggested to retrieve orderCount to Java, update it and then write it back to SQL. if possible i prefer to avoid it as it may cause serious problems (Locks on records are not needed for this task so i can not use them to avoid problems)
this should be pretty straight forward,
UPDATE books
SET orderCount = orderCount + 1
If it's about a primary key:
Also, you can AUTO INCREMENT.
CREATE TABLE Persons
(
P_Id int NOT NULL AUTO_INCREMENT,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
PRIMARY KEY (P_Id)
)
To let the AUTO_INCREMENT sequence start with another value, use the following SQL statement:
ALTER TABLE Persons AUTO_INCREMENT=100
To insert a new record into the "Persons" table, we will not have to specify a value for the "P_Id" column (a unique value will be added automatically):
INSERT INTO Persons (FirstName,LastName)
VALUES ('Lars','Monsen')

Categories

Resources