久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

MySQL 中 SUM 結果的數據類型

Datatype of SUM result in MySQL(MySQL 中 SUM 結果的數據類型)
本文介紹了MySQL 中 SUM 結果的數據類型的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在使用 SUM 時,我在將 MySQL 查詢的結果轉換為 Java 類時遇到了一點問題.

I'm having a bit of a problem with converting the result of a MySQL query to a Java class when using SUM.

在 MySQL 中執行簡單 SUM 時

When performing a simple SUM in MySQL

SELECT SUM(price) FROM cakes WHERE ingredient = 'chocolate';

price 是一個整數,看起來 SUM 有時返回一個字符串,有時返回一個整數,具體取決于 JDBC 驅動程序的版本.

with price being an integer, it appears that the SUM sometimes returns a string and sometimes an integer, depending on the version of the JDBC driver.

顯然,服務器確實告訴 JDBC 驅動程序 SUM 的結果是一個字符串,而 JDBC 驅動程序有時會方便地"將其轉換為整數.(參見Marc Matthews 的解釋).

Apparently the server does tell the JDBC driver that the result of SUM is a string, and the JDBC driver sometimes 'conveniently' converts this to an integer. (see Marc Matthews' explanation).

Java 代碼使用了一些 BeanInfo 和 內省使用查詢結果自動填充(列表)bean.但是,如果部署應用程序的服務器之間的數據類型不同,這顯然是行不通的.

The Java code uses some BeanInfo and Introspection to automagically fill in a (list of) bean(s) with the result of a query. But this obviously can't work if the datatypes differ between servers where the application is deployed.

我不在乎我得到的是字符串還是整數,但我希望始終擁有相同的數據類型,或者至少提前知道我將獲得哪種數據類型.

I don't care wether I get a string or an integer, but I'd like to always have the same datatype, or at least know in advance which datatype I'll be getting.

有沒有辦法知道 MySQL SUM 從 Java 代碼中返回哪種數據類型?或者有誰知道更好的方法來解決這個問題?

Is there some way to know which datatype will be returned by a MySQL SUM from within the Java code? Or does anyone know some better way to deal with this?

推薦答案

這只是一個猜測,但可能強制轉換為整數會迫使 MySQL 總是告訴它是一個整數.

This is just a guess, but maybe casting to integer will force MySQL to always tell it is an integer.

SELECT CAST(SUM(price) AS SIGNED) FROM cakes WHERE ingredient = 'marshmallows';

這篇關于MySQL 中 SUM 結果的數據類型的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 日韩av在线看 | 在线免费观看黄 | 中文字幕精品一区久久久久 | 欧美亚洲一区二区三区 | 日韩精品视频在线 | 青娱乐99| 中文字幕www| 超碰在线免费公开 | 免费在线观看黄色片 | 日韩精品视频在线免费观看 | 欧美日韩激情 | 午夜伦理福利 | 成年人免费在线视频 | 三级a毛片| 亚洲国产欧美日韩 | 国产第一福利 | 午夜时刻免费入口 | 一区二区三区黄色 | 免费一级黄色 | 国产成人免费 | 国产成人精品一区二区三区在线 | 午夜成人在线视频 | 91女人18毛片水多国产 | va视频 | 一区二区三区影院 | 亚洲少妇视频 | 日韩欧美一级 | 97视频在线观看免费 | 国产在线观看一区二区三区 | 成人a毛片 | 免费av大片 | 日本免费黄色网址 | 精品久久精品 | 中文字幕亚洲欧美 | 免费毛片视频 | 免费av一区二区三区 | 国产黄色三级 | 一级大片免费看 | 亚洲高清视频在线观看 | 9999精品视频| 国产wwwwww |