处理不同数据库中的不同列类型

huangapple go评论60阅读模式
英文:

Handling different column types in different databases

问题

我有一个现有的数据库,其中包含一个具有整数类型主键列的表,我计划创建一个新的数据库,该数据库将在这个表中保存更多使用大整数类型的主键列的数据。

我的Java应用程序是否可以访问任一数据库,并读取该表,而不管列是整数还是大整数类型?

这些是唯一的数据库,其中包含完全不同的数据,但具有相同的模式。

我目前还在使用PostgreSQL和Oracle,并希望确保我所做的任何操作都适用于这两种数据库。

英文:

I have an existing database which contains a table with primary key column of type int and I’m planning to create a new database which will hold more data in this table with primary key column of type bigint.

Is it possible for my Java application to access either database and read the table regardless of if the column is int or bigint?

These are unique databases with totally separate data in them but the same schema.

I also currently work with PostgreSQL and Oracle and would want to ensure anything I do works with them both.

答案1

得分: 2

你只需在你的Java类中将该字段类型简单地设置为 Long

自动地,根据int或 bigint,它将与该 Long 字段进行映射。由于Long类型占用8字节大小,它能够存储从 -9,223,372,036,854,775,8089,223,372,036,854,775,807 的所有整数。

关于原始数据类型的大小,你可以参考这里

所以不需要担心。

英文:

You can simply provide that field type as Long in your java class.

Automatically according to int or bigint, it will map with that Long field. As Long have 8 bytes size, it will able to stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

For size of primitives you can refer this.

So no need to worry.

答案2

得分: 1

  • 如果 Oracle 的数字大小小于 10,则使用 Java 的 int 数据类型。
  • 如果 Oracle 的数字大小小于 20,则使用 Java 的 long 数据类型。
  • 否则使用 Java 的 BigInteger 数据类型。
英文:
  • If oracle number size is less than 10 use java int datatype.

  • If oracle number size is less than 20 use java long datatype.

  • Otherwise use java BigInteger datatype.

huangapple
  • 本文由 发表于 2020年8月20日 00:16:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/63491105.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定