SimpleTableToJavaBean
	private static final String TAB = "\t";
	private static Map<String, String> map;

	s
		map = new HashMap<String, String>();
		map.put("TINYINT", "int");
		map.put("SMALLINT", "int");
		map.put("INT", "int");
		map.put("MEDIUMINT", "int");
		map.put("BIGINT", "long");
		map.put("INTEGER", "int");
		map.put("FLOAT", "float");
		map.put("DOUBLE", "double");
		map.put("DECIMAL", "double");
		map.put("CHAR", "String");
		map.put("VARCHAR", "String");
		map.put("VARCHAR2", "String");
		map.put("TEXT", "String");
		map.put("TINYTEXT", "String");
		map.put("MEDIUMTEXT", "String");
		map.put("LONGTEXT", "String");
		map.put("TIMESTAMP", "Date");
		map.put("DATETIME", "Date");
		map.put("DATE", "Date");
		map.put("TIME", "Date");
		map.put("TIMESTAMP_IMPORT", "import java.util.Date");
		map.put("DATETIME_IMPORT", "import java.util.Date");
		map.put("DATE_IMPORT", "import java.util.Date");
		map.put("TIME_IMPORT", "import java.util.Date");
	}

	/**
	 * <p>
	 * 根据数据库类型生成java类型信息
	 * </p>
	 *
	 * @param dataType
	 *            数据库类型
	 * @return
	 */
	public static String getPojoType(String dataType) {
		StringTokenizer st = new StringTokenizer(dataType);
		return map.get(st.nextToken());
	}

	/**
	 * <p>
	 * 根据数据库类型生成import信息
	 * </p>
	 *
	 * @param dataType
	 *            数据库类型
	 * @return
	 */
	public static String getImport(String dataType) {
		if (map.get(dataType) == null || "".equals(map.get(dataType))) {
			return null;
		} else {
			return map.get(dataType);
		}
	}

	/**
	 * <p>
	 * 通过数据库表生成JavaBean
	 * </p>
	 *
	 * @param connection
	 *            数据库连接
	 * @param tableName
	 *            表名
	 * @param packageName
	 *            包名
	 * @param dirPath
	 *            生成文件目录
	 * @throws SQLException
	 */
	public void tableToBean(Connection connection, String tableName, String packageName, String dirPath)
			throws SQLException {
		String sql = "select * from " + tableName + " where 1 <> 1";
		PreparedStatement ps = null;
		ResultSet rs = null;
		ps = connection.prepareStatement(sql);
		rs = ps.executeQuery();
		ResultSetMetaData md = rs.getMetaData();
		int columnCount = md.getColumnCount();
		StringBuffer sb = new StringBuffer();
		tableName = tableName.substring(0, 1).toUpperCase() + tableName.subSequence(1, tableName.length());
		tableName = this.dealLine(tableName);
		sb.append("package " + packageName + ";");
		sb.append(LINE);
		sb.append(LINE);
		importPackage(md, columnCount, sb);
		sb.append(LINE);
		sb.append("public class " + tableName + " {");
		sb.append(LINE);
		sb.append(LINE);
		defProperty(md, columnCount, sb);
		genSetGet(md, columnCount, sb);
		defToString(md, columnCount, sb, tableName);
		sb.append("}");
		if (!dirPath.endsWith("/") && !dirPath.endsWith("\\")) {
			dirPath = dirPath + "/";
		}
		buildJavaFile(dirPath + tableName + ".java", sb.toString());
	}

	/**
	 * <p>
	 * 属性生成get、 set方法
	 * </p>
	 *
	 * @param md
	 *            检索结果元数据
	 * @param columnCount
	 *            字段列数
	 * @param sb
	 *            字符串缓冲区
	 * @throws SQLException
	 */
	private void genSetGet(ResultSetMetaData md, int columnCount, StringBuffer sb) throws SQLException {
		for (int i = 1; i <= columnCount; i++) {
			String pojoType = getPojoType(md.getColumnTypeName(i));
			String columnName = dealLine(md, i);
			String getName = null;
			String setName = null;
			if (columnName.length() > 1) {
				getName = "public " + pojoType + " get" + columnName.substring(0, 1).toUpperCase()
						+ columnName.substring(1, columnName.length()) + "() {";
				setName = "public void set" + columnName.substring(0, 1).toUpperCase()
						+ columnName.substring(1, columnName.length()) + "(" + pojoType + " " + columnName + ") {";
			} else {
				getName = "public get" + columnName.toUpperCase() + "() {";
				setName = "public set" + columnName.toUpperCase() + "(" + pojoType + " " + columnName + ") {";
			}
			sb.append(TAB).append(getName).append(LINE);
			sb.append(TAB).append(TAB);
			sb.append("return " + columnName + ";").append(LINE);
			sb.append(TAB).append("}").append(LINE);
			sb.append(LINE);
			sb.append(TAB).append(setName).append(LINE);
			sb.append(TAB).append(TAB);
			sb.append("this." + columnName + " = " + columnName + ";").append(LINE);
			sb.append(TAB).append("}").append(LINE);
			sb.append(LINE);
		}
	}

	/**
	 * <p>
	 * 导入属性所需�
	 * </p>
	 *
	 * @param md
	 *            检索结果元数据
	 * @param columnCount
	 *            字段列数
	 * @param sb
	 *            字符串缓冲区
	 * @throws SQLException
	 */
	private void importPackage(ResultSetMetaData md, int columnCount, StringBuffer sb) throws SQLException {
		Set<String> importSet = new HashSet<String>();
		for (int i = 1; i <= columnCount; i++) {
			String im = getImport(md.getColumnTypeName(i) + "_IMPORT");
			if (im != null) {
				if (!importSet.contains(im)) {
					sb.append(im + ";");
					sb.append(LINE);
					importSet.add(im);
				}
			}
		}
	}

	/**
	 * <p>
	 * 属性定义
	 * </p>
	 *
	 * @param md
	 *            检索结果元数据
	 * @param columnCount
	 *            字段列数
	 * @param sb
	 *            字符串缓冲区
	 * @throws SQLException
	 */
	private void defProperty(ResultSetMetaData md, int columnCount, StringBuffer sb) throws SQLException {
		for (int i = 1; i <= columnCount; i++) {
			sb.append(TAB);
			String columnName = dealLine(md, i);
			sb.append("private " + getPojoType(md.getColumnTypeName(i)) + " " + columnName + ";");
			sb.append(LINE);
			sb.append(LINE);
		}
	}

	/**
	 * <p>
	 * 重写toString方法
	 * </p>
	 *
	 * @param md
	 *            检索结果元数据
	 * @param columnCount
	 *            字段列数
	 * @param sb
	 *            字符串缓冲区
	 * @param className
	 *            类名
	 * @throws SQLException
	 */
	private void defToString(ResultSetMetaData md, int columnCount, StringBuffer sb, String className) throws SQLException {
		sb.append(TAB).append("public String toString() {").append(LINE);
		sb.append(TAB).append(TAB).append("return \"").append(className).append(": [");
		for (int i = 1; i <= columnCount; i++) {
			String columnName = dealLine(md, i);
			sb.append(columnName).append("=\" + ").append(columnName).append(" + \"");
			if (i < columnCount) {
				sb.append(", ");
			}
		}
		sb.append("]\";").append(LINE);
		sb.append(TAB).append("}").append(LINE);
		sb.append(LINE);
	}

	/**
	 * <p>
	 * 下划线后一位字母大写
	 * </p>
	 *
	 * @param md
	 *            检索结果元数据
	 * @param i
	 *            第几列
	 * @return
	 * @throws SQLException
	 */
	private String dealLine(ResultSetMetaData md, int i) throws SQLException {
		String columnName = md.getColumnName(i);
		// 处理下划线情况，把下划线后一位的字母变大写；
		columnName = dealName(columnName);
		return columnName;
	}

	/**
	 * <p>
	 * 下划线后一位字母大写
	 * </p>
	 *
	 * @param tableName
	 *            表名
	 * @return
	 */
	private String dealLine(String tableName) {
		// 处理下划线情况，把下划线后一位的字母变大写；
		tableName = dealName(tableName);
		return tableName;
	}

	/**
	 * <p>
	 * 下划线后一位字母大写
	 * </p>
	 *
	 * @param str
	 *            字符串
	 * @return
	 */
	private String dealName(String str) {
		if (str.contains("_")) {
			StringBuffer names = new StringBuffer();
			String arrayName[] = str.split("_");
			names.append(arrayName[0]);
			for (int i = 1; i < arrayName.length; i++) {
				String arri = arrayName[i];
				String tmp = arri.substring(0, 1).toUpperCase() + arri.substring(1, arri.length());
				names.append(tmp);
			}
			str = names.toString();
		}
		return str;
	}

	/**
	 * <p>
	 * 生成java文件
	 * </p>
	 *
	 * @param filePath
	 *            文件路径
	 * @param fileContent
	 *            文件内容
	 */
	public void buildJavaFile(String filePath, String fileContent) {
		try {
			File file = new File(filePath);
			FileOutputStream fos = new FileOutputStream(file);
			PrintWriter pw = new PrintWriter(fos);
			pw.println(fileContent);
			pw.close();
			fos.close();
			System.out.println("Create java file completed.");
		} catch (Exception e) {
			System.out.println("Create java file error: " + e.getMessage());
		}
	}