Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a column in a MySQL table calleddead_heat_flag which data type is smallint,
and I want to represent this column as one attribute in my Java class.
What data type should I use?
As per the comment below, for MySQL's smallint, java's short should cover that value range. Of course, you could also use an int, but keep in mind that it allows many values that the database column does not.
I believe the datatype equivalent would be a short based on what I found here for java and here for a db that uses smallint. They both address the same range of values.
Short in java is equivalent to small int as there range is same.It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive).
Refer this
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html for java
https://docs.oracle.com/cd/E19501-01/819-3659/gcmaz/ for database
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Is there any Similarities between data type Dictionary and data type Array. If there are any what are them?
A dictionary maps strings to values.
An array maps integers to values.
That is about it!
So, seriously: in the end, both data structures map a "key set" to values. For dictionaries, the keys can of (almost) arbitrary type, without any constraint on them (besides being "hash able"). Whereas an array maps a consecutive range of ints to values.
From that point of view, arrays and dicts/maps are doing the same thing, but in the end, how you use them is very different.
And just for completeness: of course, the "underlying" similarity is that both are "containers": objects that "own" multiple other objects.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
In my DB I have a column named type.
In my model package there is an Enum of CREDIT, DEBIT, SAVINGS
My table can have billions of records.
The colum type has to be indexed.
I am using MySQL 5.6
And using JPA for persistency.
My question is: what data type should I use for such column?
I am thinking bout: integer or string.
If my column is int I will use EnumType.ordinal otherwise EnumType.string.
Now which data type is better in case of performance for:
searching based on this key
and to do some join?
Should I use int or string, or maybe there is some better third option?
You should use an INTEGER column if your database does not support enum types directly, since using a string type takes more space and is more difficult computationally to search.
Postgres supports user-defined enums, which the database itself will map into integers internally, and you can use EnumType.STRING with a Postgres backend. This has the advantages of enumerated types, such as easier human reading and range checking. I'm not familiar with what capabilities MySQL has in this regard.
Integers are faster than varchars, and allow sorting in the database using the natural enum ordering. But the readability suffers: 0 is less clear than 'CREDIT' when you look at rows in the database.
If sorting doesn't matter, I would first measure if the performance and space gains are worth the readability loss, and then choose accordingly. Remember that with only 3 different values and such a huge amount of rows, you'd better search on another indexed column first, that divides the amount of rows to look at by much more than 3.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am working with a dataset that has users as Strings (ie. B000GKXY4S). I would like to convert each of these users to int, so I can use Rating(user: Int, product: Int, rating: Double) class in Apache Spark ALS. What is the most efficient way to do this? Preferably using Spark Scala functions or python native functions.
If you just want any matchable String to an int - String.hashCode(). However you will have to deal with possible hash collisions. Alternatively you'd have to convert each character to its int value and append (not add) all of these together.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have been storing date records (Date().getTime()) in an SQLite database with an Integer type. I realize now that Date().getTime() is returning Long values, not Integer.
Is there any way I can rescue the date data that is already stored in the database? Going forward I can reduce the resolution of the time, to make it fit into an integer. (ie. divide by 1000, and cast to int)
I expect that forcing a long value into an integer space has truncated the most significant digits - which might work in my favour, as the dates in question have all occurred within the past 6 months, so can probably be calculated.
question
so, how exactly would the long representation of today's date map onto an integer, and how might I use that knowledge (combined with the restricted time range) to build these integers back into their original long values?
Any suggestions?
Turns out the SQLite database integer type is perfectly capable of storing long values. So the data rescue was unnecessary in the end.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Why do most programmers avoid using the float and long data types in their video tutorials?
Is it only to avoid the "0000f" and "0000L" notation?
I avoid float has it has poor precision. I would rather use double (or long with fixed precision or if I have to BigDecimal).
I suspect long is not often used as int is usually enough and many Java APIs only accept int values. e.g. array sizes and Collection/Map size() must be int.
And why should they use them? Perhaps the one reason is to avoid writing a letter indicating that the float/long type is used.
However if you don't need any special precision, why use double instead of float or long instead of int?