从数据库中搜索数据..?

发布于 2024-10-18 15:12:07 字数 339 浏览 0 评论 0原文

我有一个关于患者计费系统的项目,这是一个组织的网站。 我使用technologie jsp和java来开发这个......

在这个系统中我有不同的组织,每个组织都有它自己的数据库 我没有为这个系统维护任何中央数据库。 在这方面,我的要求是搜索必须由组织明智地完成。

例如,如果我们想知道每个组织中可用的床位数量,那么它有 给出了组织明智的可用床位数量的结果......

我的想法是将组织静态 IP 保存在我的中央数据库中 然后在需要时查询数据库..

在这方面我也有疑问.. 是否可以同时查询不同的数据库...?

请为我的问题提供任何解决方案...

提前致谢...

i have a project about patient billingsystem which is a website to a organization..
and i use technologie jsp and java to develop this....

in this system i have different organizations and each organization has it's own database
and i didn't maintain any central database for this system..
and in this my requirement is seraching must be done by the organization wise..

for example if we want to know the no of beds is available in each organization then it has
gives the result no of beds available by organization wise....

and my thought is that save the organization static ip in my central database
and then query on the database when we require..

In this also i have a doubt that..
is it possible to query on different databases on at a time...??

please give me any solution for my problem....

thanks in advance...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

物价感观 2024-10-25 15:12:07

如果IP是你必须做的一切,我想你必须这样做。

我想你最好点击主机名,因为它改变的可能性要小得多。

至于访问不同的数据库,您必须与每个数据库建立连接(尽管您可以根据大小对它们进行集群,拥有几个超级节点来访问处于该状态的所有数据库或进行并行化) )但这很容易做到。我的意思是,它几乎就这么简单(从逻辑上讲,显然你不能复制/粘贴它。)

for(DatabaseBinding db : databases) {
    Connection conn = db.spawnConnection();
    Statement stmt = ...
    ResultSet rs = stmt.execute(getBedsQuery());
    List<Bed> beds = processResultSetForBeds(rs);
    allBeds.add(beds);
}

If IP is all you have to go on, I guess you have to do it.

I imagine you'd be better off hitting the hostname, since the it's a lot less likely to change.

As far as hitting the different databases, you'll have to make a connection to each one (although it's possible you could cluster them, depending on size, having a couple super nodes that hit all the ones in that state or something to parallelize it) but it's pretty easy to do. I mean, it's almost as simple as this (logically, obviously you can't copy/paste this.)

for(DatabaseBinding db : databases) {
    Connection conn = db.spawnConnection();
    Statement stmt = ...
    ResultSet rs = stmt.execute(getBedsQuery());
    List<Bed> beds = processResultSetForBeds(rs);
    allBeds.add(beds);
}
祁梦 2024-10-25 15:12:07

我不知道有任何 DBMS 可以让您执行一次查询来访问多个数据库模式。您的两个最佳选择是:

  1. 运行一个了解每个实例的服务(最有可能通过在中央数据库中查找它们,正如您所说),该服务可以查询每个数据库并聚合结果并将它们返回到您的主程序。一旦执行此操作,您很可能会发现此中央服务的其他用途,例如初始化所有实例。
  2. 从单个数据库模式运行所有组织。这称为多租户。将组织 ID 字段添加到大多数表中,并将其添加到所有查询和大多数索引中。

哪个对您更有效受多种因素的影响。

  1. 您正在处理的组织数量与每个组织的数据量
  2. 如果您经常添加或删除组织,多租户将意味着执行此操作所需的管理工作要少得多。
  3. 如果组织之间的数据量差异很大,或者您的某些组织比其他组织活跃得多,那么将它们保存在单独的数据库实例中将允许您更精细地调整负载平衡和备份。

I don't know of any DBMSs that would let you do a single query that hits multiple database schemas. Your two best options are:

  1. Run a service that knows about each instance (most likely by looking them up in a central database as you say) that can query each database and aggregate the results and return them to your main program. Once you do this you will most likely find other uses for this central service, like initializing all instances.
  2. Run all organizations from a single database schema. This is called Multitennant. Add a field to most of your tables for the organization ID and add it to all of your queries and most of your indexes.

Which will work better for you is affected by several factors.

  1. How many organizations you're dealing with vs how much data for each
  2. If you fairly regularly add or remove organizations, multitennant will mean a lot less administration to do so.
  3. If the amount of data varies greatly between organizations, or you have some organizations that are much more active than others, then keeping them in separate database instances will allow you to more finely tune your load balancing and backups.
放低过去 2024-10-25 15:12:07

是否可以同时查询不同的数据库?

这取决于你的意思。

  • 如果数据库都使用相同的模式、表名和 SQL 方言,并且您不进行更新,并且不需要原子查询,则可以简单地保留一个到不同数据库的数据库连接池,然后发送对每个数据库进行相同的查询,然后手动合并从结果集中提取的内容。

  • 如果数据库模式(或只是表名称)不同,则 1) 您必须发送不同的查询,2) 合并结果可能会很繁琐。

  • 如果数据库使用不同的 SQL 方言,您还必须处理 SQL 语法、列类型和潜在语义的差异。

  • 跨多个数据库的原子查询和更新很困难。您需要使用支持分布式事务的分布式数据库层。

关于联合数据库系统的维基百科文章可能会帮助您了解一些问题。

is it possible to query on different databases on at a time?

It depends on what you mean.

  • If the databases all use the same schemas, table names and SQL dialect, and if you are not doing updates, and you don't need atomic queries, you can simply keep a pool of database connections to different databases, send the same query to each database, and then manually merge the stuff you pull from the resultsets.

  • If the database schemas (or just the table names) are different, then 1) you have to send different queries, and 2) merging the results may be fiddly.

  • If the databases use different SQL dialects, you've also got to deal with differences in SQL syntax, column types, and potentially semantics.

  • Atomic queries and updates across multiple databases are hard. You need to use a distributed database layer that supports distributed transactions.

The Wikipedia article on Federated Database Systems may help you understand some of the issues.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文