简单JDBCINSERT混合MySQL中不同数据库的列名称
我最近将春季框架从5.0.3升级到5.3.12,MySQL从5.7升级到8。
我正在DB中添加新列,并在模型类中添加了相应的字段。但是它无法在DB中存储新添加的字段的值。我已经讨论了该程序,该值是在模型类中修补的,但是在 simplejdbcinsert api之后,被称为db中的值并不持续存在。
代码是这样的
-DAO调用 -
logger.debug("Party Insert: " + logStr);
ID = new SimpleJdbcInsert(dataSource).withTableName("TBL_PARTY")
.usingGeneratedKeyColumns("Id").executeAndReturnKey(sqlParams).intValue();
模型类 -
public class Party extends GenericEntity{
private String partyType, name, partyCode, PANNumber;
private String registrationId;
private String WebsiteAddress;
private boolean isActive = true;
private String externalID;
private double openingBalance, closingBalance;
// new columns - fields
private String temp;
private int tempInt;
private byte tempTyniInt;
private boolean tempBol;
public String getTemp() {
return temp;
}
public void setTemp(String temp) {
this.temp = temp;
}
public String getWebsiteAddress() {
return WebsiteAddress;
}
public void setWebsiteAddress(String websiteAddress) {
WebsiteAddress = websiteAddress;
}
public String getPartyCode() {
return partyCode;
}
public void setPartyCode(String partyCode) {
this.partyCode = partyCode;
}
public String getPartyType() {
return partyType;
}
public void setPartyType(String partyType) {
this.partyType = partyType;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getRegistrationId() {
return registrationId;
}
public void setRegistrationId(String registrationId) {
this.registrationId = registrationId;
}
public boolean equals(Object obj) {
return ReflectionUtil.compareObjects(this, obj);
}
public String getExternalID() {
return externalID;
}
public void setExternalID(String externalID) {
this.externalID = externalID;
}
public double getOpeningBalance() {
return openingBalance;
}
public void setOpeningBalance(double openingBalance) {
this.openingBalance = openingBalance;
}
public double getClosingBalance() {
return closingBalance;
}
public void setClosingBalance(double closingBalance) {
this.closingBalance = closingBalance;
}
public String toString()
{
return StringUtil.objectToString(this).concat(super.toString());
}
public String getPANNumber() {
return PANNumber;
}
public void setPANNumber(String pANNumber) {
PANNumber = pANNumber;
}
public boolean getIsActive() {
return isActive;
}
public void setIsActive(boolean isActive) {
this.isActive = isActive;
}
public int getTempInt() {
return tempInt;
}
public void setTempInt(int tempInt) {
this.tempInt = tempInt;
}
public int getTempTyniInt() {
return tempTyniInt;
}
public void setTempTyniInt(byte tempTyniInt) {
this.tempTyniInt = tempTyniInt;
}
public boolean getTempBol() {
return tempBol;
}
public void setTempBol(boolean tempBol) {
this.tempBol = tempBol;
}
新列(字段)是-Temp,Tempint,Temptyniint,Tempbol。
仅供参考 - 升级后,我们将所有表的DB整理更改为 latin1_swedish_ci
utf8mb4_unicode_ci
& latin1
到 utf8mb4
的字符集
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从源找到解决方案 -
有人评论 -
属性的默认值 nullcatalogmeanscurrent 在mysql -driver 5.x和8.x中已更改。在5.x中,默认值是正确的,在8.x false中,因此在5.x databasemetadata.gettobles 中将完全从'example1'和8.x 中返回表databasemetadata.gettables 不仅将返回表从'xence1'返回表,而且还将从所有数据库中返回,这就是为什么SQL将更改为'插入人(lastName)值(?)'的原因。
解决方法,添加 nullcatalogmeanscurrent = true 在使用mySQL-Driver 8.x时,所有测试成功通过。
found the solution from the source -
https://github.com/spring-projects/spring-framework/issues/22015
someone commented -
The default value of property nullCatalogMeansCurrent has been changed in mysql-driver 5.x and 8.x. In 5.x, the default value is true, and in 8.x false, so in 5.x DatabaseMetaData.getTables will return tables exactly from 'example1', and in 8.x DatabaseMetaData.getTables will return tables not only from 'example1' but from all databases, that's why the SQL will be changed to 'INSERT INTO persons (lastname) VALUES (?)'.
Workaround, add nullCatalogMeansCurrent=true to conn url when using mysql-driver 8.x, all tests pass successfully.