如何解决根据条件在JAVA中切换数据库
我想构建一个涉及在JAVA中切换数据库连接的功能。
基本上,我有一个rest API,该API可以接受类似@ViewChildren('imageCanvas') canvas: any;
public canvasElement: any;
saveX: number;
saveY: number;
public drawing = false;
selectedColor: '#9e2956';
lineWidth: 5;
startDrawing(ev) {
if (this.canvasElement === undefined) {
this.canvasElement = this.canvas._results[0].nativeElement;
console.log('always there')
}
this.canvasElement.width = this.plt.width() + '';
this.canvasElement.height = 200;
const canvasPosition = this.canvasElement.getBoundingClientRect();
let currentX = ev.pageX - canvasPosition.x;
let currentY = ev.pageY - canvasPosition.y;
this.saveX = currentX;
this.saveY = currentY;
this.drawing = true
}
moved(ev) {
if (!this.drawing) return
const canvasPosition = this.canvasElement.getBoundingClientRect();
//console.log('canvasPosition ',canvasPosition)
let ctx = this.canvasElement.getContext('2d');
let currentX = ev.pageX - canvasPosition.x;
let currentY = ev.pageY - canvasPosition.y;
ctx.lineJoin = 'round';
ctx.strokeStyle = this.selectedColor;
ctx.lineWidth = this.lineWidth;
ctx.beginPath();
ctx.moveTo(this.saveX,this.saveY);
ctx.lineTo(currentX,currentY);
ctx.closePath();
ctx.stroke();
this.saveX = currentX;
this.saveY = currentY;
}
我想在名为/datasource/{dbName}/quantity/{quantity}
的表上执行某些操作。
ITEMS
表存在于3个不同主机上的3个不同DB中。我想在主机上运行更新查询,该主机将由请求中传递的 dbName 标识。我想将连接字符串和其他详细信息保留在API中,使用方只需传递环境名称即可在该特定环境中更新ITEMS
表。
因此,基本上,如果用户通过ITEMS
,则/datasource/PAFAT/quantity/1
主机上的ITEMS
表应该得到更新。
任何人都可以指导我如何动态切换数据源。 我可以使用Spring数据JPA,JDBC模板。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。