How to receive Unicode String from database by Java - java

I'm Vietnamese, I used to use some Unicode character ex 'Việt Nam', â, ẵ, ấ, ị, đ, Đ, Ệ, Ố, ư..., I'm having a exercise relate with insert/receive data from database, I'm using Java. I can not receive data from database without many error with there character. Who can help me ?

It whould be better to understand your problem with the exact error code. But as I underestand you, your problem is that you have something in database ( and it's okthere ) but when you want to read and show it, you face with some problems. With these background I think:
you have to use utf-8 to store and read data.
your application have to support your locale. ( for instance as I know JDK doesn't support fa_IR locale, so it may be your problem)
But as there are lots of vietnamians java application, your problem should belongs to your DAL.
Provide complete error and ensure that your data is stored correctly in your database.

Try Java 7 if you want to use Access database.
Otherwise, use a different DBMS that Java currently supports queries or updates with Unicode characters.
Java Programming with Vietnamese

Related

how to compare a value's encoding of string type with a specific encoding in java?

I'm told to write a code that get a string text and check if its encoding is equal the specific encoding that we want or not. I've searched a lot but I didn't seem to find anything. I found a method (getEncoding()) but it just works with files and that is not what I want. and also I'm told that i should use java library not methods of mozilla or apache.
I really appreciate any help. thanks in advance.
What you are thinking of is "Internationalization". There are libraries for this like, Loc4j, but you can also get this using java.util.Locale in Java. However in general text is just text. It is a token with a certain value. No localization information is stored in the character. This is why a file normally provides the encoding in the header. A console or terminal can also provide localization using certain commands/functions.
Unless you know the source encoding and the token used you will have a limited ability to guess what encoding is used in the other end. If you still would want to do this you will need to go into deeper areas such as decryption where this kind of stuff usually is done using statistic analysis. This in turn requires databases on the usage of different tokens and depending on the quality of the text, databases and algorithms a specific amount of text is required. Special stuff, like writing Swedish with eg. US encoding (like using a for å and ä or o for ö) will require more advanced analysis.
EDIT
Since I got a comment that encoding and internationalization is different entities I will add some comments. It is possible to work with different encodings working plainly with English (like some English special characters). It is also possible to work with encodings using for example Charset. However for many applications using different encodings it may still be efficient to use Locale, since this library can do a lot of operations on text with different encodings.
Thanks for ur answers and contribution but these two link did the trick. I had already seen these two pages but it didn't seem to work for me cause I was thinking about get the encoding directly and then compare it with the specific one.
This is one of them
This is another one.

Is there a Java library which will convert Olsen timezone ids to Windows timezone ids

I have a legacy Windows application which reads data from a database. One of the columns is 'TimeZoneInfoId'. Which in the legacy world was written by another windows application so it stores the Windows string:
TimeZoneInfo.CurrentTimeZone.StandardName
I now need to write to this table from a Java application. So I'm trying to find a library that will map a time zone ID from the tz database (formerly known as the Olson database) to the windows timezone id. Ideally I'd like to use a library that in theory I could update to later releases in the future as I've read that timezone info can sometimes change.
I've searched a bit online already, and the answers I've found generally say either write your own mapping/lookup or use NodaTime and do the conversion in .NET (if you really need a library that can be updated).
I can't update the legacy code (wihtout a complete re-write) so just asking the question here since most of the answers I've found are a little old so maybe there is something new that I can avail of ;)
If not it will have to be a custom lookup function I hfea.
Well, assuming you meant the value came from TimeZoneInfo.Local.Id, then you can do this conversion. If it came from TimeZone.CurrentTimeZone.StandardName, then there will be some entries that fail because StandardName is a localized string, and the English form doesn't necessarily match the Id
Getting to your question, you could just look at the source XML data in CLDR, and parse it similar to how I described here.
Or, if you really want a library, consider that ICU4J has the methods getWindowsId and getIDForWindowsID that uses the same data to do the conversion. However, ICU can be really big, so if you only need it for this one thing then you might be better off going to the XML directly.

How can I show arabic query search from MYSQL by JavaFX?

SELECT * FROM `employee` WHERE `name` LIKE "%شريف%"
Above query works fine and find the element by phpmyAdmin query but using it inside JavaFX doesn't get it.
And get the english searchs, So what I need to add in java to permit me search by Arabic.
As per my above comments, I guess it to be a encoding - decoding issue of Java and has nothing specific to do with JavaFX and I also assume that you are not getting any exceptions. You have to use a proper standard while inserting as well as retrieving data. Helpful information is there at , How to store arabic text in mysql database using python?
Refer this article to work only on bytes so your application is always properly internationalized , Byte Encodings and Strings
Refer this one too as how to set encoding in Java , How can I insert arabic word to mysql database using java
Your console might be UTF8 enabled so you are able to match strings there and see Arabic characters.
Hope it helps.

Writing a MYSQL backed Java Back end Service for Dummies

So I want to do the simplest possible thing.
Assume I have a MYSQL enabled hosting service.
In it, I have a database storyland and a table story-->(id, title, text)
I only know how to write Java programs in eclipse that run on my computer and do homework assignments well...:)
Now I want to
1) write a Java program that is hosted on my server that would compute and return (for example) the number of characters of text stored in the entire MYSQL database
Then I also only have experience with writing PHP programs that talk directly to MYSQL via forms e.t.c but now i want to
2) be able to display a page index.php that says
echo "Welcome to storyland, there are $textcount
characters of text in all stories here";
where $textcount is the number returned by the java service.
I would appreciate really specific answers for this really "simple" specific example..to get me started. I'd also appreciate answers/resources that do not lean too heavily on external libraries/software since i want to be able to understand how those libraries work to be able to decide how to use them in future.
Thanks!
A design thought: I'd be tempted to have one more column - size, and have that precomputed for each blob of text, so you wouldn't have to calculate that (which might be expensive to count a blob > varchar size). Then I'd just issue a SUM over that column and be done: SELECT SUM(size) from mytable;
That would make the db work real simple, a simple INSERT and SELECT system really.
You need to have your own server, or a server that supports java, else this is not possible.
Even if you have a server that supports java, why do this with java when you can do it with php, the bottleneck will probably be the database anyhow.

Reading Unicode Text from Java ResultSet

how to read unicode text from java resultset?
rs.getString() returns a Java String which is Unicode by definition.
If you get mangled characters, you have to configure your database driver to use the right encoding for the connection to the database.
Just read the strings. All strings in Java are unicode already. If you're having problems, then:
It could be a diagnostic problem - you may be reading the right data out of the ResultSet but displaying it so it looks like you haven't read it properly
It could be a configuration problem - there may be something you need to do when connecting to the database so that it determines the right encoding to use
It could be a database problem - the database may not be configured to store full Unicode data
It could be a database schema problem - the particular column you're using may be configured using a column type which doesn't support full Unicode
It could be a problem in the data, e.g. with another program incorrectly submitting data.
I've seen all of these before now. You should use detailed logging (e.g. of the individual characters, in hex) to work out whether you've got the data correctly or not - that will tell you where to look next.
If you are using DataSource (f.e. com.mysql.jdbc.jdbc2.optional.MysqlDataSource) you can directly set channel encoding to UTF8 like ds.setEncoding("UTF-8")

Categories