I have a Java Swing application for a client that works internationally. A few times per year a piece of text is copied from a Microsoft application like Outlook into a JTextArea, and then stored in a UTF-8 database. Upon retrieval, the database throws an SQL exception that it can't decode some character.
I'm trying to comprehend the copy-paste part of the process. Is there any information about how copying from windows to Java works exactly? Can't find it.
Windows is setup using CP1252, but the text in Outlook definitely is using non CP1252 characters, so the copied data has an encoding. And when that is pasted into JTextArea, does Java transcode that to UTF-16 (it's internal string encoding)?
Related
I am new to JAVA. I wanted a JAVA code to convert a text file coming from Unix to a text file that goes to Linux server. So, its a character conversion code from UTF-16 TO UTF-8. The text file goes tthrough oracle database before it reaches linux server. I need this conversion because some special symbols are getting converted to garbage values. Please help Java Experts :)
I wrote a program that reads from a file has Arabic text encoded with ANSI.
I made a runnable jar of that program.
It run perfectly on my Laptop, however, when I run it on another laptop the Arabic characters turn into a messy symbols.
So what to do?
Make sure your end system is having the fonts required to display those letters if not bundle it with your application.
Check whether you are reading the file content UTF-8 (Or appropriate encoding format).
I'm having troubles with special characters like í, ó, ñ, and so on in my MYSQL database.
I've read a lot about character set, collation, utf and son on but I might not being able to proper apply it to this problem. I'm not sure if the problem is with my tables or when reading the source file and encoding. I'm working on netbeans developing an interface that generates specific reports
Here I briefly explain the process when the issue occurs
There is a table where are located the path files for the Excel files that are requested.
My code takes that path, opens the file using the JXL library.
Then it starts reading every cell that it is indicated in the code and export the data to the tables indicated (HERE IS WHERE IN THE TABLES APPEARS THIS � IN EVERY SPECIAL CHARACTER)
The data is correctly exported to the several tables, and there is no problem with that, only special characters that are replaced with this �
So, after researching I've tried this
As I'm using MYSQL workbench I've alter every table in the collation from utf8 - default TO utf8 - utf8_spanish_ci and utf8 - utf8_spanish_ci
I've tried also changing the collation to utf16 - default collation, utf_spanish_ci, bin, etc
And also, I've tried using the utf32 collation.
The netbeans encoding it is correctly set to utf-8
I've tried exploring the JAVA functions that connects to MYSQL, I'm using this connection but I haven't found nothing about encoding:
private Connection conecta=null;
String Driver="com.mysql.jdbc.Driver";
String Url="jdbc:mysql://XXX.XXX.XXX.XX/BLAABLA";
Class.forName(Driver);
conecta=DriverManager.getConnection(Url,User,Password);
The database when I manually insert data that contains special characters, it correctly displays whenever I need it, but when I try using the automatically insert option as previously described that reads the file using jxl library and so on, then it happens the � thing.
I've found some useful answers here in stackoverflow but all are related to specific cases of php, html, xml and so on. All the answers about java are related to the utf8 collation
So I hope you can provide me some help.
Am I not doing the collation correctly?, Should I try something weird directly in the console? Does mysql workbench is forbidding something?
I'm open to all kind of suggestions but if the answer is like "You must use another library because jxl does not work with that" please consider that my project is almost done, and re-do this with a different library could take me much more time as I already have expected. Please, if JXL is the problem probably there must be something else. Nothing is impossible right?
Thanks for the time.
Excel files by default uses windows-1255 (Cp1255) codification. So when you read those bytes from the excel file you need to treat them with that charset and then store them with utf8.
I am writing a java application on Ubuntu Linux that reads in a text file and creates an xml file from the data. Some of the text contains curly apostrophes and quotes that I convert to straight apostrophes and quotes using the following code:
dataLine = dataLine.replaceAll( "[\u2018|\u2019]", "\u0027" ).replaceAll( "[\u201C|\u201D]", "\u005c\u0022" );
This works fine, but when I port the jar file to a Mac OSX machine, I get three question marks where I should get straight apostrophes and quotes. I created a test application on the Mac using the same line of code to do the conversion and the same test file for input and it worked fine. Why doesn't the jar file created on the Linux machine work correctly on a Mac? I thought java was supposed to be cross platform compatible.
Chances are you'tr not reading the file correctly to start with. You haven't shown how you're reading the file, but my guess is that you're just using FileReader, or an InputStreamReader without specifying the encoding. In that case, the default platform encoding is used - and if that's not the actual encoding of the file, you won't be reading the right characters. You should be able to detect that without doing any replacement at all.
Instead, you should use a FileInputStream and wrap it in an InputStreamReader with the correct encoding - which is likely to be UTF-8 as it's XML. (You should be able to check this easily.)
I am building an app that takes information from java and builds an excel spreadsheet. Some of the information contains international characters. I am having an issue when Russian characters, for example, are rendered correctly in Java, but when I send those characters to Excel, they are not rendered properly. I initially thought the issue was an encoding problem, but I am now thinking that the problem is simply not have the Russian language pack loaded on my Windows 7 machine.
I need to know if there is a way for a Java application to "force" Excel to show international characters.
Thanks
Check the file encoding you're using is characters don't show up. Java defaults to platform native encoding (Win-1252 for Windows) instead of UTF-8. You can explicitly set the writers to use UTF-8 or Cyrillic encoding.