Several exceptions and workarounds that are encountered in the project that involve MySQL (go)

Source: Internet
Author: User

This article transferred from: http://blog.csdn.net/haoren_e/archive/2010/05/14/5590912.aspx

This project uses MySQL database, did not have much contact before, so encountered a lot of problems, in this small summary:

(1)com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:Communications link Failure

The meaning of the name: timeout, unable to connect

So the solution is also very well done:

Add wait_timeout=1814400 in My.ini, (21*3600*24) for 21 days, and modify the wait time-out period.

(2) Com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:Data Source rejected establishment of Connection, message from server: "Too many connections"

Cause: Because the number of concurrent connections set in the My.ini in your MySQL installation directory is too low or the system is busy, the number of connections is fully occupied.

How to resolve:
Open MySQL install directory open My.ini find Max_connections (in about line 93rd) default is 1001 like set to 500~1000 more appropriate, restart MySQL, so 1040 error solved.
max_connections=1000

(3) Always heard that MySQL is not case-sensitive, indeed, the Windows platform is really case-insensitive, but once the program is ported to Linux, there is a problem. Because mysql is sensitive to capitalization under Linux.

Workaround: Locate the MY.CNF configuration file under the ETC folder and locate the mysqld:

Lower_case_table_names=1 (Let the case is not sensitive) different numbers mean different meanings, if you want to know more, you can check the Internet, not in detail here.

(4) There was a time when inserting data into the table: Com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:You has anerror in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use near ' £¬photo_url= ' PHOTOS/NON.G If ', phone= ' 013901290001 ', id_type= '? ¨ª??? ¡è ', id_num= ' at line 1,

WORKAROUND: Because my SQL statement is insert INTO tb_process_form_attendance (Runid,key), and key in MySQL is the keyword, so can not insert, error, add two points on the head of key (anti-quote, it in the keyboard ~ on this key). Can be done: ' key ', ah, really do not know ah ~

(5) Today when writing SQL encountered a said in the MySQL4.1 neutron query is not allowed to use LIMIT, the manual also explicitly indicated this version of the MySQL doesn' t yet support ' limit & in /all/any/some subquery.

WORKAROUND: Such statements are not executed correctly.
SELECT * FROM table where ID in (select id from table limit 10);

But, as long as you have another layer on the line. Such as:

SELECT * FROM table where ID in (select t.id from (SELECT * from table limit) as T)

(6) Notunique Table/alias

A non-Unique table or alias appears in the SQL statement.

Workaround:

1. Check that the SQL statement where the problem occurred is using the same table name, or that the same table alias is defined.

2. Check that the field names to be queried in the SELECT statement are duplicates or not defined.

Continue to summarize, constantly updated ~ hope to share with you ~

Several exceptions and workarounds that are encountered in the project that involve MySQL (go)

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.