This question already has answers here:
Why can't primitive data types be "null" in Java?
(8 answers)
Closed 3 years ago.
#Column(name="NU_MAGASIN")
private short nuMagasin;
i create entities from table and this column in my db got null value but the didn;t accept it
and i got this message
Can not set short field supplycam.entities.Nomenclature.nuMagasin to null value
To have an answer on this question I add the code how it must look like:
#Column(name="NU_MAGASIN")
private Short nuMagasin;
In Java short, int, long, float, double, byte, char, boolean are primitive types and not nullable. But there exists a wrapper type for each of these. Usually starting with a capital letter.
Related
I'd like to add a large string (above 76k characters) to CLOB column in Oracle database.
I need to run a script from liquibase framework.
How can achive this?
Simple insert
INSERT INTO table_clob (clob_column) VALUES (to_Clob('string above 72000 chars...'));
with and without to_clob() method is returning exception like:
ORA-01704: string literal too long
Cannot load data from file as described here with procedure: https://oracle-base.com/articles/8i/import-clob
as I don't have priviliges to any directory
Searched google but didn't enounter any solution for my requirement.
Any advice?
UPDATE:
After hours of searching finally found a workaround here: https://stackoverflow.com/a/49817056/1622703
It is not sufficient as I need to cut the text for 3 chunks manually (with around 30k chars), but it works.
Now just need to figure our how to do it dynamically in case that the string will have vary lenghts of chars (above 10k chars for example).
A hard-coded string enclosed in single quotes is known as a string literal. An example is 'Hello world'. Another example is the very long string you are trying to insert in the table. By contrast, 'abc' || 'def' is a string expression but it is not a string literal. Similarly, to_char(sysdate, 'yyyy-mm-dd') is a string expression, but not a literal. "Literal" means constant, hard-coded text.
The issue you are facing has nothing to do with insert, or to_clob(), or the data type of columns in your table, etc. It only has to do with the string literal itself.
In Oracle, a string literal can be at most 4000 bytes long (or 32767 bytes if the database is set up with extended MAX_STRING_SIZE). PERIOD! There is no way around it.
So, the question is, how can you ever get a string as long as the one you have into a table with a CLOB column. The answer depends on how you are receiving the string in the first place. The best option would be if it came in chunked already - as a collection of strings, with a tag (an id) to keep track of which fragment belongs to which CLOB and an ordinal number (to show if it's the first chunk, the second, etc.) Then you could re-assemble them using TO_CLOB() on the first chunk, plus the concatenation operator.
If your process is to type 72000 characters at the keyboard, you will have to type 4000 of them at a time, enclose in single quotes, and use the concatenation operator (essentially doing by hand what I described above). You would also have to use TO_CLOB() on the first fragment (otherwise the concatenation will fail).
Another option is for the string to come as a value, from some application that supports long strings (something compatible with Oracle's CLOB) and that can hand over such values to the Oracle database without the need to write out the hard-coded string in full.
So, the ball is in your court. The first question is, Where is the long string coming from in the first place?
This question already has answers here:
Date formats from device based on locale
(5 answers)
Closed 5 years ago.
I want a method that returns the local date format as a string.
E.g., the method would return the string "dd/MM/yyyy" for UK users and "MM/dd/yyyy" for USA users.
What you are looking for is NSDateFormatter's dateFormatFromTemplate:options:locale: method. This takes a template containing the elements of the date you wish included and returns the appropriate format for the supplied locale.
This question already has answers here:
Spring data jpa - How to combine multiple And and Or through method name
(4 answers)
Closed 3 years ago.
Hi I am working with spring-data and I am using repositories, then i just figured out that one method is not working properly for the AND-OR distribution. Here is me method.
long countByNameAndStartDateBetweenOrFinishDateBetween(String name, Date startDateFrom, Date startDateTo, Date endDateFrom, Date endDateTo);
And i would like to recover the number of users with a particular name and wheen the startDate is in between a range or the finishDate is in between a range.
But he is combining Name&startDate - Or finishDate so return the number of records with the finishDate in between.
Is possible to do it with spring data? Should i use #Query annotation and write my query there?
Thanks!
Spring Repositories naming convention gives you only that much. If the method naming convention doesn't work for you, use the #Query annotation
I'm working on a project in MVC 3 (first time using!). One question I keep running into is how to specify datatypes. For example, why have a field of type Nvarchar that has a length of 4000 when you only need a length of 10. As far as I can tell, there is no definitive compilation of specifying server data types for your database. I've been fairly successful so far (Below are some of the ones I've found), and please correct me if I am wrong. My main question is if there is a way to specify a Tinyint (1 byte) in MVC 3.
Here's some of the popular ones I've found:
Smallint: Specify field as Int16
Bigint: Specify field as Int64
Nvarchar(n): Add [StringLength(n)] above your variable in your Model
bit: Seems simple, but for first-time programmers - specify your field as a bool.
DateTime: There are so many flavors of DateTime, and to specify, initialize your field in your model as DateTime, and specify the type by placing [DataType(DataType.YourPreferredFormat)] above the variable, where "YourPreferredFormat" is a date/time related option of the enum DataType (DateTime, Date, Time, Duration). I'm not 100% clear on this though, so if anyone knows how each correlates, that would be great to know.
Per this answer to c-sharp-equivalent-of-sql-server-2005-datatypes it appears that you need to use Byte.
I currently use INT as type for primary key in JavaDB (Apache Derby), but since I'm implementing an distributed system I would like to change the type to java.util.UUID. A few questions about this:
What datatype in JavaDB/Derby should I use for UUID? I have seen CHAR(16) FOR BIT DATA been mentioned but I don't know much about it. Is VARCHAR(16) an alternative?
How should I use it with JDBC? E.g. in an PreparedStatement, how should I set and get an UUID?
If I later would likte to change database to SQL Server, is there a compatible datatype to java.util.UUID?
Simply, How should I use UUID with JavaDB/Derby and JDBC?
UUID is a 128 bit value. The CHAR(16) FOR BIT DATA type reflects that it is bit data stored in character form for conciseness. I don't think VARCHAR(16) would work because it doesn't have the bit flag. The database would have to be able to convert the binary data to character data which deals with encoding and is risky. More importantly, it wouldn't buy you anything. Since a UUID is always 128 bits, you don't get the space savings from using VARCHAR over CHAR. So you might as well use the intended CHAR(16) FOR BIT DATA.
With JDBC, I think you use the get/setBytes() method since it is dealing with small amounts of binary data. (Not positive, would have to try this)
And no idea about the SQL Server part.
If you still want to use the UUID object in your code you can use fromString to create UUID objects from the DB and toString to store them in the DB.
You could convert the UUID to a string and store it as VARCHAR. Most UUID string formats are similar to this one: 32 digits separated by hyphens: 00000000-0000-0000-0000-000000000000, so then you'd want a VARCHAR(36), or make it something like VARCHAR(64) if you please, since it doesn't hurt to have extra 'space' available in your VARCHAR -- only the actual digits are stored.
Once you've converted it to a string, just call Statement.SetString to include it in your INSERT statement.