心法领悟178:枚举类型与switch语句。
package com.mingrisoft.enums;
public enum JDBCInfo {
DRIVER, URL, USERNAME, PASSWORD;
public String getJDBCInfo(JDBCInfo info) {
switch (info) {
case DRIVER:
return "com.mysql.jdbc.Driver";
case URL:
return "jdbc:mysql://localhost:3306/db_database";
case USERNAME:
return "mr";
case PASSWORD:
return "mingrisoft";
default:
return null;
}
}
public static void main(String[] args) {
for (JDBCInfo info : JDBCInfo.values()) {
System.out.println(info + ":" + info.getJDBCInfo(info));
}
}
}
//Output:
DRIVER:com.mysql.jdbc.Driver
URL:jdbc:mysql://localhost:3306/db_database
USERNAME:mr
PASSWORD:mingrisoft