Notes for Java Web applications under UbuntuLinux

Source: Internet
Author: User
Not long ago, the machines used for the company were really slow. I was so angry that I had formatted Windows and installed the Ubuntu operating system. However, the Java program encountered a problem: 1. Default Character Set setting of MySQL: Before recreating a data table, set the MYSQL database: first, modify the default Character Set setting of the MYSQL database. Before recreating a database, set the default character set to UTF8. Operation Method: Stop the MYSQL server: sudo/etc/init.

Not long ago, the machines used for the company were really slow. I was so angry that I had formatted Windows and installed the Ubuntu operating system.

However, a problem occurs in the Java program:

1. Default Character Set settings for MySQL: MYSQL database settings before recreating a data table:

First, modify the default Character Set settings of the MYSQL database. Before recreating a database, set the default character set to UTF8. Procedure:

Stop MYSQL Server: sudo/etc/init. d/mysql stop
Edit the MYSQL configuration file: sudo gedit/etc/mysql/my. cnf
Add the following under [mysqld:

Default-character-set = utf8
Init_connect = 'set NAMES utf8'

Add the following under [client:

Default-character-set = utf8

After saving, start the MYSQL server

Sudo/etc/init. d/mysql start

Go to MYSQL: mysql-u root-p
Mysql> show variables like 'character % ';
+ -------------------------- + ---------------------------- +
| Variable_name | Value |
+ -------------------------- + ---------------------------- +
| Character_set_client | utf8 |
| Character_set_connection | utf8 |
| Character_set_database | utf8 |
| Character_set_filesystem | binary |
| Character_set_results | utf8 |
| Character_set_server | utf8 |
| Character_set_system | utf8 |
| Character_sets_dir |/usr/share/mysql/charsets/|
+ -------------------------- + ---------------------------- +
8 rows in set (0.00 sec)


The modification is successful.


2. The case sensitivity of database tables. In MySQL, database and table pairs are stored in directories and files under those directories. Therefore, the sensitivity of the operating system determines the case sensitivity of the database and table names. This means that the database and table names are case-insensitive in Windows and are case-sensitive in most types of Unix systems.

It is strange that the column name and column alias are case-insensitive in all cases, while the table alias is case-sensitive.

To avoid this problem, you 'd better define all the database naming rules in combination with lowercase letters and underscores instead of any uppercase letters.

Alternatively, you can force the-O lower_case_table_names = 1 parameter to start mysqld (if -- defaults-file =... \ my. if the cnf parameter is used to read the specified configuration file and start mysqld, you need to add a line lower_case_table_names = 1 in the [mysqld] section of the configuration file ). In this way, MySQL automatically converts all table names to lowercase characters when creating and searching (this option is 1 by default in Windows and 0 in Unix. From MySQL 4.0.2, this option also applies to the database name ).

When you change this option, you must first convert the old table name to lowercase letters before starting mysqld.

In other words, if you want to retain the case-sensitive characters when creating a table in the database, set this parameter to 0: lower_case_table_names = 1. Otherwise, you will find that the same sqldump script imports different results in different operating systems (all uppercase characters in Windows are changed to lowercase letters ).

3. JDK default file encoding character set. I am responsible for importing and exporting data in the developed system. When importing CSV files, JDK may set the default file character set in Linux to UTF-8, so if it involves reading and writing text content files, it is best to specify the FileInputStream encoding character set, or use the JVM startup parameter-Dfile. encoding = gbk to set the default file encoding character set.

 

This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/zhangwei217245/archive/2009/07/06/4325582.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.