{"id":2261,"date":"2025-08-27T18:41:30","date_gmt":"2025-08-27T10:41:30","guid":{"rendered":"https:\/\/note.ui11.cc\/?p=2261"},"modified":"2025-08-27T18:41:30","modified_gmt":"2025-08-27T10:41:30","slug":"mysql%e5%92%8cjava%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e5%af%b9%e7%85%a7","status":"publish","type":"post","link":"https:\/\/note.ui11.cc\/index.php\/2025\/08\/27\/mysql%e5%92%8cjava%e4%b8%ad%e7%9a%84%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e5%af%b9%e7%85%a7\/","title":{"rendered":"mysql\u548cjava\u4e2d\u7684\u6570\u636e\u7c7b\u578b\u5bf9\u7167"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">\u6574\u6570\u7c7b\u578b<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>MySQL \u6570\u636e\u7c7b\u578b<\/th><th>\u8bf4\u660e<\/th><th>Java \u5bf9\u5e94\u7c7b\u578b<\/th><th>\u5907\u6ce8<\/th><\/tr><\/thead><tbody><tr><td><code>TINYINT<\/code><\/td><td>1 \u5b57\u8282\uff0c\u8303\u56f4\uff1a-128 ~ 127<\/td><td><code>byte<\/code><\/td><td>\u65e0\u7b26\u53f7\u65f6\u8303\u56f4 0~255\uff0c\u53ef\u5bf9\u5e94<code>short<\/code><\/td><\/tr><tr><td><code>SMALLINT<\/code><\/td><td>2 \u5b57\u8282\uff0c\u8303\u56f4\uff1a-32768 ~ 32767<\/td><td><code>short<\/code><\/td><td>\u65e0\u7b26\u53f7\u65f6\u8303\u56f4 0~65535\uff0c\u53ef\u5bf9\u5e94<code>int<\/code><\/td><\/tr><tr><td><code>MEDIUMINT<\/code><\/td><td>3 \u5b57\u8282\uff0c\u8303\u56f4\uff1a-8388608 ~ 8388607<\/td><td><code>int<\/code><\/td><td>MySQL \u7279\u6709\u7c7b\u578b\uff0cJava \u4e2d\u65e0\u5bf9\u5e94\uff0c\u7528<code>int<\/code><\/td><\/tr><tr><td><code>INT<\/code>\/<code>INTEGER<\/code><\/td><td>4 \u5b57\u8282\uff0c\u8303\u56f4\uff1a-2^31 ~ 2^31-1<\/td><td><code>int<\/code><\/td><td>\u6700\u5e38\u7528\u7684\u6574\u6570\u7c7b\u578b<\/td><\/tr><tr><td><code>BIGINT<\/code><\/td><td>8 \u5b57\u8282\uff0c\u8303\u56f4\uff1a-2^63 ~ 2^63-1<\/td><td><code>long<\/code><\/td><td>\u5b58\u50a8\u5927\u6574\u6570\u65f6\u4f7f\u7528<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">. \u6d6e\u70b9 \/ \u5c0f\u6570\u7c7b\u578b<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>MySQL \u6570\u636e\u7c7b\u578b<\/th><th>\u8bf4\u660e<\/th><th>Java \u5bf9\u5e94\u7c7b\u578b<\/th><th>\u5907\u6ce8<\/th><\/tr><\/thead><tbody><tr><td><code>FLOAT<\/code><\/td><td>4 \u5b57\u8282\u5355\u7cbe\u5ea6\u6d6e\u70b9\u6570<\/td><td><code>float<\/code><\/td><td>\u7cbe\u5ea6\u8f83\u4f4e\uff0c\u9002\u5408\u5b58\u50a8\u8fd1\u4f3c\u503c<\/td><\/tr><tr><td><code>DOUBLE<\/code><\/td><td>8 \u5b57\u8282\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u6570<\/td><td><code>double<\/code><\/td><td>\u7cbe\u5ea6\u9ad8\u4e8e<code>FLOAT<\/code>\uff0c\u5e38\u7528<\/td><\/tr><tr><td><code>DECIMAL(M,D)<\/code><\/td><td>\u9ad8\u7cbe\u5ea6\u5c0f\u6570\uff08M \u4e3a\u603b\u4f4d\u6570\uff0cD \u4e3a\u5c0f\u6570\u4f4d\uff09<\/td><td><code>java.math.BigDecimal<\/code><\/td><td>\u9002\u5408\u91d1\u878d\u7b49\u9700\u7cbe\u786e\u8ba1\u7b97\u7684\u573a\u666f\uff08\u5982\u91d1\u989d\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u5b57\u7b26\u4e32\u7c7b\u578b<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>MySQL \u6570\u636e\u7c7b\u578b<\/th><th>\u8bf4\u660e<\/th><th>Java \u5bf9\u5e94\u7c7b\u578b<\/th><th>\u5907\u6ce8<\/th><\/tr><\/thead><tbody><tr><td><code>CHAR(n)<\/code><\/td><td>\u56fa\u5b9a\u957f\u5ea6\u5b57\u7b26\u4e32\uff08n \u4e3a\u957f\u5ea6\uff09<\/td><td><code>String<\/code><\/td><td>\u957f\u5ea6\u4e0d\u8db3\u65f6\u7528\u7a7a\u683c\u586b\u5145\uff0c\u9002\u5408\u77ed\u5b57\u7b26\u4e32<\/td><\/tr><tr><td><code>VARCHAR(n)<\/code><\/td><td>\u53ef\u53d8\u957f\u5ea6\u5b57\u7b26\u4e32\uff08n \u4e3a\u6700\u5927\u957f\u5ea6\uff09<\/td><td><code>String<\/code><\/td><td>\u4ec5\u5b58\u50a8\u5b9e\u9645\u957f\u5ea6\uff0c\u8282\u7701\u7a7a\u95f4\uff0c\u5e38\u7528<\/td><\/tr><tr><td><code>TEXT<\/code><\/td><td>\u957f\u6587\u672c\uff08\u6700\u5927 65535 \u5b57\u8282\uff09<\/td><td><code>String<\/code><\/td><td>\u9002\u5408\u5b58\u50a8\u5927\u6587\u672c\uff08\u5982\u6587\u7ae0\u5185\u5bb9\uff09<\/td><\/tr><tr><td><code>MEDIUMTEXT<\/code><\/td><td>\u4e2d\u7b49\u957f\u5ea6\u6587\u672c\uff08\u6700\u5927 16MB\uff09<\/td><td><code>String<\/code><\/td><td>\u6bd4<code>TEXT<\/code>\u5b58\u50a8\u66f4\u5927\u7684\u6587\u672c<\/td><\/tr><tr><td><code>LONGTEXT<\/code><\/td><td>\u6781\u5927\u6587\u672c\uff08\u6700\u5927 4GB\uff09<\/td><td><code>String<\/code><\/td><td>\u5b58\u50a8\u8d85\u5927\u578b\u6587\u672c\u5185\u5bb9<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u65e5\u671f\u65f6\u95f4\u7c7b\u578b<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>MySQL \u6570\u636e\u7c7b\u578b<\/th><th>\u8bf4\u660e<\/th><th>Java \u5bf9\u5e94\u7c7b\u578b<\/th><th>\u5907\u6ce8<\/th><\/tr><\/thead><tbody><tr><td><code>DATE<\/code><\/td><td>\u65e5\u671f\uff08\u683c\u5f0f\uff1aYYYY-MM-DD\uff09<\/td><td><code>java.sql.Date<\/code><\/td><td>\u4ec5\u5305\u542b\u5e74\u6708\u65e5<\/td><\/tr><tr><td><code>TIME<\/code><\/td><td>\u65f6\u95f4\uff08\u683c\u5f0f\uff1aHH:MM:SS\uff09<\/td><td><code>java.sql.Time<\/code><\/td><td>\u4ec5\u5305\u542b\u65f6\u5206\u79d2<\/td><\/tr><tr><td><code>DATETIME<\/code><\/td><td>\u65e5\u671f\u65f6\u95f4\uff08\u683c\u5f0f\uff1aYYYY-MM-DD HH:MM:SS\uff09<\/td><td><code>java.sql.Timestamp<\/code><\/td><td>\u5305\u542b\u5e74\u6708\u65e5\u65f6\u5206\u79d2\uff0c\u7cbe\u5ea6\u5230\u79d2<\/td><\/tr><tr><td><code>TIMESTAMP<\/code><\/td><td>\u65f6\u95f4\u6233\uff08UTC \u65f6\u95f4\uff0c\u683c\u5f0f\u540c DATETIME\uff09<\/td><td><code>java.sql.Timestamp<\/code><\/td><td>\u53d7\u65f6\u533a\u5f71\u54cd\uff0c\u9002\u5408\u8bb0\u5f55\u4e8b\u4ef6\u53d1\u751f\u65f6\u95f4<\/td><\/tr><tr><td><code>YEAR<\/code><\/td><td>\u5e74\u4efd\uff08\u683c\u5f0f\uff1aYYYY\uff09<\/td><td><code>short<\/code>&nbsp;\u6216&nbsp;<code>int<\/code><\/td><td>\u8303\u56f4 1901~2155\uff0c\u53ef\u7528\u6574\u6570\u7c7b\u578b\u5b58\u50a8<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">5. \u4e8c\u8fdb\u5236 \/ \u5b57\u8282\u7c7b\u578b<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>MySQL \u6570\u636e\u7c7b\u578b<\/th><th>\u8bf4\u660e<\/th><th>Java \u5bf9\u5e94\u7c7b\u578b<\/th><th>\u5907\u6ce8<\/th><\/tr><\/thead><tbody><tr><td><code>BINARY(n)<\/code><\/td><td>\u56fa\u5b9a\u957f\u5ea6\u4e8c\u8fdb\u5236\u6570\u636e<\/td><td><code>byte[]<\/code><\/td><td>\u7c7b\u4f3c<code>CHAR<\/code>\u7684\u4e8c\u8fdb\u5236\u7248\u672c<\/td><\/tr><tr><td><code>VARBINARY(n)<\/code><\/td><td>\u53ef\u53d8\u957f\u5ea6\u4e8c\u8fdb\u5236\u6570\u636e<\/td><td><code>byte[]<\/code><\/td><td>\u7c7b\u4f3c<code>VARCHAR<\/code>\u7684\u4e8c\u8fdb\u5236\u7248\u672c<\/td><\/tr><tr><td><code>BLOB<\/code><\/td><td>\u4e8c\u8fdb\u5236\u5927\u5bf9\u8c61\uff08\u6700\u5927 65535 \u5b57\u8282\uff09<\/td><td><code>byte[]<\/code>&nbsp;\u6216&nbsp;<code>InputStream<\/code><\/td><td>\u5b58\u50a8\u56fe\u7247\u3001\u6587\u4ef6\u7b49\u4e8c\u8fdb\u5236\u6570\u636e<\/td><\/tr><tr><td><code>MEDIUMBLOB<\/code><\/td><td>\u4e2d\u7b49\u4e8c\u8fdb\u5236\u5bf9\u8c61\uff08\u6700\u5927 16MB\uff09<\/td><td><code>byte[]<\/code>&nbsp;\u6216&nbsp;<code>InputStream<\/code><\/td><td>\u5b58\u50a8\u8f83\u5927\u7684\u4e8c\u8fdb\u5236\u6570\u636e<\/td><\/tr><tr><td><code>LONGBLOB<\/code><\/td><td>\u6781\u5927\u4e8c\u8fdb\u5236\u5bf9\u8c61\uff08\u6700\u5927 4GB\uff09<\/td><td><code>byte[]<\/code>&nbsp;\u6216&nbsp;<code>InputStream<\/code><\/td><td>\u5b58\u50a8\u8d85\u5927\u578b\u4e8c\u8fdb\u5236\u6570\u636e<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">6. \u5176\u4ed6\u7279\u6b8a\u7c7b\u578b<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>MySQL \u6570\u636e\u7c7b\u578b<\/th><th>\u8bf4\u660e<\/th><th>Java \u5bf9\u5e94\u7c7b\u578b<\/th><th>\u5907\u6ce8<\/th><\/tr><\/thead><tbody><tr><td><code>BOOLEAN<\/code>\/<code>BOOL<\/code><\/td><td>\u5e03\u5c14\u7c7b\u578b\uff080=false\uff0c1=true\uff09<\/td><td><code>boolean<\/code><\/td><td>MySQL \u4e2d\u672c\u8d28\u662f<code>TINYINT(1)<\/code>\u7684\u522b\u540d<\/td><\/tr><tr><td><code>ENUM<\/code><\/td><td>\u679a\u4e3e\u7c7b\u578b\uff08\u9884\u5b9a\u4e49\u503c\u96c6\u5408\uff09<\/td><td><code>String<\/code><\/td><td>\u5b58\u50a8\u679a\u4e3e\u4e2d\u7684\u5b57\u7b26\u4e32\u503c<\/td><\/tr><tr><td><code>SET<\/code><\/td><td>\u96c6\u5408\u7c7b\u578b\uff08\u591a\u4e2a\u9884\u5b9a\u4e49\u503c\uff09<\/td><td><code>String<\/code><\/td><td>\u5b58\u50a8\u9017\u53f7\u5206\u9694\u7684\u9009\u4e2d\u503c<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u6574\u6570\u7c7b\u578b MySQL \u6570\u636e\u7c7b\u578b \u8bf4\u660e Java \u5bf9\u5e94\u7c7b\u578b \u5907\u6ce8 TINYINT 1 \u5b57\u8282\uff0c\u8303\u56f4\uff1a-128 ~  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2261","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts\/2261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/comments?post=2261"}],"version-history":[{"count":1,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts\/2261\/revisions"}],"predecessor-version":[{"id":2262,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts\/2261\/revisions\/2262"}],"wp:attachment":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/media?parent=2261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/categories?post=2261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/tags?post=2261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}