
DatabaseType d1 = (DatabaseType)EnumParse(typeof(DatabaseType), "MSSQL", true);
DatabaseType d2 = (DatabaseType)EnumParse(typeof(DatabaseType), "0", true);
结果 d1=DatabaseTypeMSSQL;
d2=DatabaseTypeUnDefined;
ENUM('value1','value2',) 65535个成员 1或2字节
但是用的比较少。。。
你得写程序自己处理下,大概是下边这样
import javasqlConnection;
import javasqlDriverManager;
import javasqlResultSet;
import javasqlStatement;
public class EnumTesting {
Connection connection;
Statement statement;
public EnumTesting() {
try {
ClassforName("commysqljdbcDriver")newInstance();
connection = DriverManager
getConnection("jdbc:mysql://192168125/testuser=spider&password=spider");
} catch (Exception e) {
Systemerrprintln("Unable to find and load driver");
Systemexit(1);
}
}
public void doWork() {
try {
statement = connectioncreateStatement();
ResultSet rs = statement
executeQuery("SHOW COLUMNS FROM enumtest LIKE 'status'");
rsnext();
String enums = rsgetString("Type");
Systemoutprintln(enums);
int position = 0, count = 0;
String[] availableEnums = new String[10];
while ((position = enumsindexOf("'", position)) > 0) {
int secondPosition = enumsindexOf("'", position + 1);
availableEnums[count++] = enumssubstring(position + 1,
secondPosition);
position = secondPosition + 1;
Systemoutprintln(availableEnums[count - 1]);
}
rsclose();
statementclose();
connectionclose();
} catch (Exception e) {
eprintStackTrace();
}
}
public static void main(String[] args) {
Enum e = new Enum();
edoWork();
}
}
mysql怎么获取数据表字段enum类型的默认值 本节主要内容: MySQL数据类型之枚举类型ENUM MySQL数据库提供针对字符串存储的一种特殊数据类型:枚举类型ENUM,这种数据类型可以给予我们更多提高性能、降低存储容量和降低程序代码理解的技巧
将枚举的值转换为对应的名字
inthashCode = ColorRedGetHashCode(); stringenumParseStr = EnumParse(typeof(Color), hashCodeToString())ToString();EnumParse()得到的值是object类型的,我们要转换的是值,得到的是名字,因此ToString()得到名字。
将枚举的名字转换为对应的值
stringstr = ColorRedToString(); intenumParseInt = ConvertToInt32(EnumParse(typeof(Color), str));这里要转换的是名字,得到的是值,因此用ConvertToInt32()得到该值。
int a=1;
Url u=(Url)a;
var a = typeof(Url)GetField(uToString())GetCustomAttributes(typeof(DescriptionAttribute), false)FirstOrDefault() as DescriptionAttribute;
var d = aDescription;
//d就是你想要的值
以上就是关于c# 大家是如何处理根据字符串来获取枚举值的全部的内容,包括:c# 大家是如何处理根据字符串来获取枚举值的、java resultset 获取枚举型数据、怎么拿到Mysql一张表里某enum类型字段的所有值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)