相同的准备语句,多个数据库,相同的架构 [英] Same prepared statement, multiple databases, same schema

查看:103
本文介绍了相同的准备语句,多个数据库,相同的架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个ms sql服务器数据库x1,x2,x3,... xn,实际上是所有相同的模式类型,而一个数据库y是不同的并保存管理数据.

I have multiple ms sql server databases x1, x2, x3, ... xn, effectively all the same schema type and one database y that is different and holds management data.

我使用的是jdbc预准备语句,有时需要一次在一个程序中的多个x数据库上执行同一预准备语句.

I am using jdbc prepared statements and there are occasions when the same prepared statement needs to be executed on multiple x databases from one program at one occasion.

如果准备好的语句的SQL未指示数据库:

If the prepared statement's SQL does not indicate a database:

准备好的语句是否仅与服务器相关联,并且是否在根据上下文选择的数据库上执行(例如执行)?遵循USE语句.

Is the prepared statement associated just with the server, and if executed is executed on a database selected according to context, e.g. following a USE statement.

或者它是否永久与连接URL中的默认数据库相关联?如果是这样,并且我仍然想使用预先准备的语句,即使架构和语句在原则上是相同的,也必须为每个数据库创建一个预先准备的语句.​​

OR is it forever associated with the default database in the connection URL? If so, and I still want to use preprepared statements, must I create a prepared statement for every single database, even though the schemas and statements are in principal identical.

推荐答案

我可以肯定(但不是100%肯定)已准备好的语句已绑定到特定数据库.鉴于查询计划必须评估在每个数据库中都不同的索引和表统计信息.

I am pretty certain (but not 100% positive) that a prepared statement is bound to a specific database. Given that a query plan has to evaluate index and table statistics which would differ in each database.

由于这似乎是一个内部系统,并且SQL注入可能不是问题-我将使用直接执行或stmt.executeQuery(query).

And since this appears to be an internal system, and SQL injection may not be an issue - I would use a direct execute or stmt.executeQuery(query).

这篇关于相同的准备语句,多个数据库,相同的架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆