Same prepared statement, multiple databases, same schema

非 Y 不嫁゛ 提交于 2020-01-05 03:58:04

问题


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.

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.

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

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.

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.


回答1:


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.

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).



来源:https://stackoverflow.com/questions/39475066/same-prepared-statement-multiple-databases-same-schema

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!