I have been doing CRUD operation on database, but i could not find any direct method for the getting the data type char
in database.
我一直在对数据库进行CRUD操作,但我找不到任何直接的方法来获取数据库中的数据类型char。
Though i achieved the output using the getString(String column_name)
of the result set, but i wonder why there does not exist any method like getChar(String column_name)
, since String and Character are two different data types.
虽然我使用结果集的getString(String column_name)来实现输出,但我想知道为什么不存在任何方法,如getChar(String column_name),因为String和Character是两种不同的数据类型。
4 个解决方案
#1
5
Refer to the link and see the table 3-1 and you will get decent idea that why there does not exists getChar(String column_name)
.
请参阅链接并查看表3-1,您将很好地了解为什么不存在getChar(String column_name)。
Summary: Mapping of char is to String. So there exists getString(String column_name)
for the char data type
摘要:char的映射是String。因此char数据类型存在getString(String column_name)
#2
14
As MySQL sees it, it's all Strings
because it has no type for a single character. Sure, you can set CHAR
or VARCHAR
to sizes of max one, but this is a special case and you generally don't want to make methods for special cases when the functionality is already there.
正如MySQL所见,它是所有字符串,因为它没有单个字符的类型。当然,您可以将CHAR或VARCHAR设置为max one的大小,但这是一种特殊情况,并且您通常不希望在功能已存在的情况下为特殊情况创建方法。
Just extract the Java char
from the resulting String
, as such:
只需从生成的String中提取Java char,如下所示:
getString(column_name).charAt(0)
#3
4
It is because a Char in MySQL doesn't really mean a singular char value, it really means a array of chars. In java an array of chars is represented as a String, hence the same method.
这是因为MySQL中的Char并不真正意味着单个char值,它实际上意味着一系列字符。在java中,字符数组表示为String,因此方法相同。
#4
1
Databases often have only one type for representing all the strings of characters.
数据库通常只有一种类型用于表示所有字符串。
A char is only a special case: a string with one character, so it would not be really useful to add this type.
char只是一种特殊情况:一个包含一个字符的字符串,因此添加此类型并不是很有用。
And don't be fooled by their name like CHAR. :)
不要被像CHAR这样的名字所迷惑。 :)
#1
5
Refer to the link and see the table 3-1 and you will get decent idea that why there does not exists getChar(String column_name)
.
请参阅链接并查看表3-1,您将很好地了解为什么不存在getChar(String column_name)。
Summary: Mapping of char is to String. So there exists getString(String column_name)
for the char data type
摘要:char的映射是String。因此char数据类型存在getString(String column_name)
#2
14
As MySQL sees it, it's all Strings
because it has no type for a single character. Sure, you can set CHAR
or VARCHAR
to sizes of max one, but this is a special case and you generally don't want to make methods for special cases when the functionality is already there.
正如MySQL所见,它是所有字符串,因为它没有单个字符的类型。当然,您可以将CHAR或VARCHAR设置为max one的大小,但这是一种特殊情况,并且您通常不希望在功能已存在的情况下为特殊情况创建方法。
Just extract the Java char
from the resulting String
, as such:
只需从生成的String中提取Java char,如下所示:
getString(column_name).charAt(0)
#3
4
It is because a Char in MySQL doesn't really mean a singular char value, it really means a array of chars. In java an array of chars is represented as a String, hence the same method.
这是因为MySQL中的Char并不真正意味着单个char值,它实际上意味着一系列字符。在java中,字符数组表示为String,因此方法相同。
#4
1
Databases often have only one type for representing all the strings of characters.
数据库通常只有一种类型用于表示所有字符串。
A char is only a special case: a string with one character, so it would not be really useful to add this type.
char只是一种特殊情况:一个包含一个字符的字符串,因此添加此类型并不是很有用。
And don't be fooled by their name like CHAR. :)
不要被像CHAR这样的名字所迷惑。 :)